Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:38:36+00:00 2026-06-11T03:38:36+00:00

So I think its because I am merging a user id into the discussion

  • 0

So I think its because I am merging a user id into the discussion upon create that does it, because I am validating both discussion content and title….

Discussion Model

class Discussion < ActiveRecord::Base  
  attr_accessible :user_id, :content, :title

  has_many :discussion_comments, :dependent => :destroy
  belongs_to :user

  validate :content, :presence => true,
                     :length => {:minimum => 10, :maximum => 254}
  validate :title, :presence => true,
                   :length => {:minimum => 10, :maximum => 254}
end

Discussion Controller

  def create
    @discussion = Discussion.create(params[:discussion].merge(:user_id => current_user.id))
    if @discussion.save
      redirect_to tasks_path, :flash => {:success => 'Created a new discussion'}
    else
      redirect_to tasks_path, :flash => {:error => 'Cannot create empty discussions.'}
    end
  end

Any ways, Every time I try and save an empty form, it gives me the success message when it should give me the error message.

Discussion Form

<%= form_for @discussion do |f| %>

    <p><%= f.label :title %>
    <%= f.text_field :title %></p>

    <p><%= f.label :content %>
    <%= f.text_area :content %></p>

    <p><%= f.submit %></p>

<% end %>

As stated I think it has something to do with the fact that I am merging the user id upon create, how ever the validation should stop the whole create process – no?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:38:38+00:00Added an answer on June 11, 2026 at 3:38 am

    Is this Rails 3.x? Try using validates not validate. Could just be a simple typo.

    So…

    class Discussion < ActiveRecord::Base  
      ...
    
      validates :content, :presence => true,
                          :length => {:minimum => 10, :maximum => 254}
      validates :title, :presence => true,
                        :length => {:minimum => 10, :maximum => 254}
    end
    

    Ref: http://guides.rubyonrails.org/active_record_validations_callbacks.html#presence

    I link to the presence example, but it should be validates regardless of which options you pass to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have project that is giving me some headache and i think its because
I have to ask this question because I'm stuck, and I think its because
Ok, guys, I think that's the right place to ask a question, because it's
I think its easy to create form via only html and do not use
Does anyone know off a way or maybe think its possible to connect Node.js
I think its because I am not referring to the array properly. I'm new
my application is still crashing I don't know I think its because the shared
I always get confused on how to properly format json. I think its because
R is not generating in my android application package and I think it's because
I don't think my code's the problem because it's working on my local server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.