I have this checkbox. How can I put that code in one line? <% if @repair_ticket.send_email == 1%> <%= check_box_tag "send_email", @repair_ticket.send_email, 1 , { :disabled => true } %> <% end %> <% if @repair_ticket.send_email == 0%> <%= check_box_tag "send_email", @repair_ticket.send_email, checked false , { :disabled => true } %> <% 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 -~----------~----~----~----~------~----~------~--~---
Try: <%= check_box_tag "send_email", @repair_ticket.send_email, @repair_ticket.send_email, {:disabled => true } %> If @repair_ticket.send_email was set as a boolean value in a migration, ROR should interpret the send_email field as true or false and thus correctly check/uncheck the checkbox. -Chris On Mar 26, 8:31 am, John Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have this checkbox. How can I put that code in one line? > > <% if @repair_ticket.send_email == 1%> > <%= check_box_tag "send_email", @repair_ticket.send_email, 1 , { > :disabled => true } %> > <% end %> > <% if @repair_ticket.send_email == 0%> > <%= check_box_tag "send_email", @repair_ticket.send_email, checked > false , { :disabled => true } %> > <% end %> > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
On 26 Mar 2008, at 13:49, Christopher Hazlett wrote:> > Try: > <%= check_box_tag "send_email", @repair_ticket.send_email, > @repair_ticket.send_email, {:disabled => true } %> > > If @repair_ticket.send_email was set as a boolean value in a > migration, ROR should interpret the send_email field as true or false > and thus correctly check/uncheck the checkbox. >or even <%= check_box ''repair_ticket'', ''send_email'', :disabled => true %> (but that will result in a different parameter name) Fred> -Chris > > On Mar 26, 8:31 am, John Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> I have this checkbox. How can I put that code in one line? >> >> <% if @repair_ticket.send_email == 1%> >> <%= check_box_tag "send_email", @repair_ticket.send_email, 1 , { >> :disabled => true } %> >> <% end %> >> <% if @repair_ticket.send_email == 0%> >> <%= check_box_tag "send_email", @repair_ticket.send_email, >> checked >> false , { :disabled => true } %> >> <% end %> >> -- >> Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
If you move the some of it to the helper, you can do this HELPER ---------------- def send_email_checkbox(send_email) if send_email == 1 value = "1" elsif send_email == 0 value = "checked = false" end return check_box_tag ''send_email'', @repair_ticket.send_email, value, :disabled => true end VIEW --------------- <%= send_email_checkbox(@repair_ticket.send_email) %> - Brad On Mar 26, 8:31 am, John Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have this checkbox. How can I put that code in one line? > > <% if @repair_ticket.send_email == 1%> > <%= check_box_tag "send_email", @repair_ticket.send_email, 1 , { > :disabled => true } %> > <% end %> > <% if @repair_ticket.send_email == 0%> > <%= check_box_tag "send_email", @repair_ticket.send_email, checked > false , { :disabled => true } %> > <% end %> > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---