To reiterate a post I made on a related topic 
<https://groups.google.com/d/msg/rubyonrails-core/GtAQDk0SCA0/lXNx0sSSAQAJ>
...

Rather than alter all the individual helper methods which take a :class option 
(e.g. link_to, content_tag), why not just use a helper method to generate 
the finalized list of classes?

For example,

link_to "Hello", root_url, class: *class_set(selected: selected?, btn: 
true)*

There's an existing gem which was inspired by React's classSet and exposes 
this exact functionality:
https://github.com/nLight/css-class-string 
<https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FnLight%2Fcss-class-string&sa=D&sntz=1&usg=AFQjCNH9pvUYuzVOx9jVdzsNl7-Nqd39fA>

On Monday, October 24, 2016 at 8:12:14 PM UTC-4, [email protected] wrote:
>
> Well this is old, but still relevant :) I've seen the replies, but i've we 
> do it the way we wanted and just because all the other attributes are doing 
> it that way, i think you're doing it wrong. Rails is meant to please the 
> developer, making painful constructs just to make a link selected or 
> current is just crazy.
>
> I'd would love it if rails would have a class: {selected: selected?, btn: 
> true}
>
> Rails, is elegant, makes sense and just works. Some hashes get special 
> treatment, thats fine.
>
> :class should be one of them. 
>

-- 
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 https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to