Hey guys, I got a statuses model which holds all my applications statuses, they are differentiated by their status type. In my application I have some invoices that I want to be able to set their invoice.status using radio buttons (which are created in my view from the statuses table). Does anyone have any idea on how to achieve this, as there appears to be little help available online for such things. thanks a bunch dave -- 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 -~----------~----~----~----~------~----~------~--~---
Dave Smith wrote:> Hey guys, > > I got a statuses model which holds all my applications statuses, they > are differentiated by their status type. > > In my application I have some invoices that I want to be able to set > their invoice.status using radio buttons (which are created in my view > from the statuses table). > > Does anyone have any idea on how to achieve this, as there appears to be > little help available online for such things. > > thanks a bunch > > davenay ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
Seek out the API docs grasshopper... From http://api.rubyonrails.org/ Module ActionView::Helpers::FormHelper radio_button(object_name, method, tag_value, options = {}) Returns a radio button tag for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). If the current value of method is tag_value the radio button will be checked. Additional options on the input tag can be passed as a hash with options. Let''s say that @post.category returns "rails": radio_button("post", "category", "rails") radio_button("post", "category", "java") Or radio_button("user", "receive_newsletter", "yes") radio_button("user", "receive_newsletter", "no") -- 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 -~----------~----~----~----~------~----~------~--~---
In your case, have the appropriate controller read in the statuses info and hand that to the view... @statuses = Status.find(:all, :order => ''something'') Then the view (or a partial) can do something like: @statuses.each do |this_status| radio_button("application", "status", this_status.value) end or sumfink like that... -- 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 -~----------~----~----~----~------~----~------~--~---
Can''t resist adding this gratuitous and unsolicited advice: If an application can only have one status at a time, resist any urge you might feel to store status in a series of boolean fields in applications. Instead, have your controller just store the id of the selected status in application.status_id. That way you don''t have to worry that an application might wind up with >1 of those booleans checked at a time, you should be able to add/rename statuses at will, etc. -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Ar Chron Sent: Tuesday, January 13, 2009 9:01 AM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: radio buttons and whatnot In your case, have the appropriate controller read in the statuses info and hand that to the view... @statuses = Status.find(:all, :order => ''something'') Then the view (or a partial) can do something like: @statuses.each do |this_status| radio_button("application", "status", this_status.value) end or sumfink like that... -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ar Chron wrote:> In your case, have the appropriate controller read in the statuses info > and hand that to the view... > > @statuses = Status.find(:all, :order => ''something'') > > Then the view (or a partial) can do something like: > > @statuses.each do |this_status| > radio_button("application", "status", this_status.value) > end > > or sumfink like that...brill... i understand. what i have done it put it in a partial in my page form. I have a projects page with a list of project_tasks and I want to use the same code in this page and have the status in the form of a radio button for each task, so I have put the code into a partial in projects view. This is my partial. <% Status.find_all_by_type("Project").each do |s|%> <%= f.radio_button :status_id, s.id %> <%= f.label :status_id, s.name %> <% end %> I am trying to make a link to the partial on the projects show.html.erb page. I know the code below this will not work, but am trying to adapt it to take the task instead of the project form object. <%= render :partial => "statuses", :locals => { :f => f } %> obviously my partial here will be expecting a project form object.. any clues? <% form_for(@project) do |f| %> <% for task in @project_tasks %> <%= render :partial => "statuses", :locals => { :f => f } %> <% end %> <% end %> I want it to take the task object instead any ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
> <% form_for(@project) do |f| %> > <% for task in @project_tasks %> > <%= render :partial => "statuses", :locals => { :f => f } %> > <% end %> > <% end %> > > I want it to take the task object instead > > any ideas?bump -- 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 -~----------~----~----~----~------~----~------~--~---
Dave Smith wrote:> >> <% form_for(@project) do |f| %> >> <% for task in @project_tasks %> >> <%= render :partial => "statuses", :locals => { :f => f } %> >> <% end %> >> <% end %> >> >> I want it to take the task object instead >> >> any ideas? > > bumpdont worry i fixed it. just moved the form into the loop cheers guys -- 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 -~----------~----~----~----~------~----~------~--~---