Here's a very simple example. def link_to_post(post) html_class = ["post"] html_class << "active" if post.active? link_to(post.title, post, class: html_class) end
On Wed, Mar 5, 2014 at 9:09 AM, Sergio Campamá <[email protected]>wrote: > could you provide an example of one of those helpers? > > -------------------------------------- > Sergio Campamá > [email protected] > > > > On Wed, Mar 5, 2014 at 1:04 PM, Andrew Kaspick <[email protected]> wrote: > >> -1 >> >> I don't see why 'class' would get the special treatment when all other >> attributes could be candidates too and that style is very inconsistent with >> pretty much all of rails and not particularly clear either. >> >> I personally just use a helper if logic is required for attributes. >> >> >> On Wed, Mar 5, 2014 at 10:36 AM, Stefan Schüßler <[email protected]>wrote: >> >>> When dealing with conditional class attribute values in HTML tags, I >>> often find myself writing code like: >>> >>> link_to(post.title, post, class: "post #{post.active? ? "active" : >>> ""}") >>> >>> The code would be much cleaner if we allowed a hash syntax: >>> >>> link_to(post.title, post, class: {"post" => true, "active" => >>> post.active?}) >>> >>> The implementation is straightforward: >>> >>> >>> https://github.com/sos4nt/rails/commit/a9ed04f75ce9db46af6cbdefa64dfb09fb3eb73a >>> >>> What do you think? >>> >>> -Stefan >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Core" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/rubyonrails-core. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/rubyonrails-core. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
