I have a registration form that submits information outside of the object. Specifically, they''re checkboxes asking if the user wishes to be contacted. They''re not related to an attribute of the User object, and if there are errors, the form is reloaded with all of the user information, but the check boxes blanked out. Is there a ''Rails Magic'' way to keep the values or do I have to hack it up? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 11/17/06, Jason Norris <jasonmnorris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a registration form that submits information outside of the > object. Specifically, they''re checkboxes asking if the user wishes to be > contacted. They''re not related to an attribute of the User object, and > if there are errors, the form is reloaded with all of the user > information, but the check boxes blanked out. Is there a ''Rails Magic'' > way to keep the values or do I have to hack it up? > > > >Jason, It seems to me an ok_to_contact field for the User model would be useful to keep around and persist to the database. Why would you not make this an attribute of the User model? -- Zack Chandler http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
We actually have a ''subscription'' model which tracks which mailing lists the users want to be a part of. This form will just email our salespeople if the boxes are checked. We don''t need to track it. We actually fixed it by putting :checked => (params[:contact][:this_item] != 0)? ''checked'' : false On each checkbox, but that seems icky. Zack Chandler wrote:> On 11/17/06, Jason Norris <jasonmnorris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> I have a registration form that submits information outside of the >> object. Specifically, they''re checkboxes asking if the user wishes to be >> contacted. They''re not related to an attribute of the User object, and >> if there are errors, the form is reloaded with all of the user >> information, but the check boxes blanked out. Is there a ''Rails Magic'' >> way to keep the values or do I have to hack it up? >> >> > > Jason, > > It seems to me an ok_to_contact field for the User model would be > useful to keep around and persist to the database. Why would you not > make this an attribute of the User model? > > -- > Zack Chandler > http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
Jason Norris wrote:> I have a registration form that submits information outside of the > object. Specifically, they''re checkboxes asking if the user wishes to be > contacted. They''re not related to an attribute of the User object, and > if there are errors, the form is reloaded with all of the user > information, but the check boxes blanked out. Is there a ''Rails Magic'' > way to keep the values or do I have to hack it up?The most basic method is to recycle form data using the params hash directly: check_box_tag :contact_ok, some_value, !params[:contact_ok].nil? If you want the box initially ticked you can set params[:contact_ok] to some value in your controller code for the page GET. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You could have the magic if you wanted to In your user class, simply make use of attribute accessors. attr_accessor :contact_for_promotion, :contact_for_something_else Then you can do <%=check_box "user", "contact_for_promotion" %> And the magic should work just fine. You''ll even be able to do things with them in the model then. HOWEVER... your situation seems like they should actually be database colums... that way 1. They persist and can be changed later so users can opt in / out 2. You simply need to do user.find_all_by_contact_for_promotion.collect{|u| u.email}) to get an array of email addresses to send messages to :) On 11/17/06, Mark Reginald James <mrj-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> > > Jason Norris wrote: > > I have a registration form that submits information outside of the > > object. Specifically, they''re checkboxes asking if the user wishes to be > > contacted. They''re not related to an attribute of the User object, and > > if there are errors, the form is reloaded with all of the user > > information, but the check boxes blanked out. Is there a ''Rails Magic'' > > way to keep the values or do I have to hack it up? > > The most basic method is to recycle form data using the params > hash directly: > > check_box_tag :contact_ok, some_value, !params[:contact_ok].nil? > > If you want the box initially ticked you can set params[:contact_ok] > to some value in your controller code for the page GET. > > -- > We develop, watch us RoR, in numbers too big to ignore. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---