How can I put that code in one line?

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 %>

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 S. [email protected]

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

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 S. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs