Ruby on Rails Saturday, June 21, 2014

I have a user model with a number of fields representing the user profile.

When a user is first signing up, I have an initial question I want to ask that is a one time and not part of the user profile.

In the model, I have:
    attr_accessor :completed_cfdym
    validates(:completed_cfdym, inclusion: { in: ['Yes', 'No'], message: "%{value} is not a valid response"} )

In the view, I have:

    <% f.label :completed_cfdym, "Have you Completed 'A Conversation for The Difference You Make'", class: 'span5'  %>
    <%= f.select :completed_cfdym, {'' => nil, 'Yes' => 'Yes', 'No' => 'No'}, {}, { :class => 'span1' } %><br>

In the controller, in the create method, I have:

    if params[:completed_cfdym] == 'Yes'
        Conversation.create_holder(@user)
    end

Looking at the console model in the development environment, I see that completed_cfdym is returning nil, 'Yes', or 'No' based on what I select.

However:

The validation fails and, when it returns to the forms page, the completed_cfdym is not preserved - it always returns to ''

Also, if I remove the validates, the test in the controller does not seem to be able to recognize the 'Yes'.

What am I missing?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/df94e4af-e6c3-47bc-95bc-8151e21f6083%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment