Or wrap with ():

  *link_to(post.title, post, class: ["post", ("active" if post.active?)])*


On Wed, Mar 5, 2014 at 2:47 PM, Nicolás Sanguinetti <
[email protected]> wrote:

> Sorry, it should be ["post", post.active? && "active"]
>
>
> On Wed, Mar 5, 2014 at 3:23 PM, Stefan Schüßler <[email protected]> wrote:
>
>> That array syntax is invalid.
>>
>> On Wednesday, March 5, 2014 6:16:01 PM UTC+1, Nicolás Sanguinetti wrote:
>>
>>> You can pass Arrays to the `class:` option and it will do what you
>>> expect it to:
>>>
>>>     link_to(post.title, post, class: ["post", "active" if post.active?])
>>>
>>> Cheers,
>>> -foca
>>>
>>>
>>> On Wed, Mar 5, 2014 at 1:36 PM, 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/a9ed04f75ce9db46af6cbdefa64dfb
>>>> 09fb3eb73a
>>>>
>>>> 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.
>



-- 
At.
Carlos Antonio

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

Reply via email to