I''ve got a User model with an ActiveRecord method called ''isAdmin'' that determines wether or not that user is an administrator. And in order to create these users I have new_user.rhtml paired with _user_form.rhtml, in which there is a checkbox that is supposed to determine the value of ''isAdmin'' - 0 or 1. I''ve tried several variations of things I found in my Rails book and on the web, and absolutely nothing has worked thus far. When I turn on validation in the User model, I keep getting told that my checkbox is blank, which is impossible, since if it''s checked isAdmin = 1 and if it''s not checked isAdmin = 0. Any suggestions? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''ve run across this. If you''re using the form_for(:model) format it seems to generate the necessary hidden input with value=0 whereas the check_box_tag didn''t. If I recall correctly. Once I moved to the form_for format those kinds of problems haven''t popped up again. Hope that helps. RSL On 12/25/06, Kyle Stegerwald <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''ve got a User model with an ActiveRecord method called ''isAdmin'' that > determines wether or not that user is an administrator. And in order to > create these users I have new_user.rhtml paired with _user_form.rhtml, > in which there is a checkbox that is supposed to determine the value of > ''isAdmin'' - 0 or 1. I''ve tried several variations of things I found in > my Rails book and on the web, and absolutely nothing has worked thus > far. When I turn on validation in the User model, I keep getting told > that my checkbox is blank, which is impossible, since if it''s checked > isAdmin = 1 and if it''s not checked isAdmin = 0. > > Any suggestions? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Russell Norris wrote:> I''ve run across this. If you''re using the form_for(:model) format it > seems > to generate the necessary hidden input with value=0 whereas the > check_box_tag didn''t. If I recall correctly. Once I moved to the > form_for > format those kinds of problems haven''t popped up again. > > Hope that helps. > > RSLI tried the form_for model using this code and I''m still getting the "isAdmin can''t be blank" error, despite the fact that I know that the paramaters are being passed correctly, i.e. it shows me that I''m passing isAdmin as either a 0 or a 1. Anyway, here''s the code... ignore the html. <% form_for :user, @user, :url => { :action => "create_user" } do |u| %> <tr><td>Username:</td><td><%= u.text_field :name %></td></tr> <tr><td>Password:</td><td><%= u.text_field :password %></td></tr> <tr><td>Grant admin powers? <%= u.check_box :isAdmin %></td></tr> </table> <br> <input type = "submit" value = "Create New User"> <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---