Pablo wrote:> Hello
>
> Is it possible to pass a condition to radio_button_tag helper to check
> if smth is true or not?
>
>
> <%for brand in @brands%>
> <p><%=radio_button_tag "product[brand_id]", brand.id,
:checked => true%>
> <%= brand.name %>
> </p>
> <%end%>
>
> I want to make it "checked" only for chosen brand in the
database. I
> have done similar with check_box_tag on habtm relation with include? but
> here it does not seem to work
>
> thx
I found a solution
First in a radio_button_tag
<%for brand in @brands%>
<p><%=radio_button_tag "product[brand_id]", brand.id,
checked?(brand.name)%>
<%= brand.name %>
</p>
<%end%>
And then in a helper
def checked?(brand_name)
@product.brand.name == brand_name rescue nil
end
It seems to work! I put rescue nil for /new action as i am using the
same form and @product does not exist. I hope this is the right
solution.
--
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
-~----------~----~----~----~------~----~------~--~---