I think having a Haml tag output nothing if its script content is nil
might violate the "principle of least surprise."
Also, if your views are littered with conditionals, to me it sounds
more like you have a problem in your application logic. I'm guessing
your view originally had one or two links like the ones you described,
and then eventually grew. Sounds like it's time to refactor.
You could consider refactoring your view or partial into 2, one for
managers and another for regular users.
If it's a fully different view, your controller could do something like
if permitted_to? :manage, :users
render "manager_controls"
else
render "user_controls"
Otherwise if it's a partial you could do more or less the same thing
in your view:
- if permitted_to? :manage, :users
= render :partial => "manager_controls"
- else
= render :partial => "user_controls"
Either way, if you want to suppress the tag in a one-liner, there's always:
%li= link_to("Users", users_path) if permitted_to? :manage, :users
-Norman
On Fri, Oct 2, 2009 at 8:02 AM, Dr Nic Williams <[email protected]> wrote:
> Sounds valid, and interesting to me.
> On Fri, Oct 2, 2009 at 7:58 PM, [email protected] <[email protected]> wrote:
>>
>> Hi!
>>
>> I have been using haml almost years now :-)
>>
>> Now I have got one small idea, just need your opinion if this does not
>> go against some fundamental haml way. If not then I would dig deeper
>> and write some patch or smth.
>>
>> Currently:
>>
>> %li= nil
>>
>> It will return empty element <li></li> however I would prefer if it
>> does not return anything at all. Why?
>>
>> Cos I'm using declarative authorization gem and often write code like:
>>
>> %li= link_to "Users", users_path if permitted_to? :manage, :users
>>
>> However sometimes I have css style for li elements and empty element
>> got style as well. So at the moment I have to write code what is not
>> so nice and one liner any more:
>>
>> - if permitted_to? :manage, :users
>> %li= link_to "Users", users_path
>>
>> I have quite many permitted_to? methods in my views, so that's why I
>> thought I need some global option for Nil not to return any output.
>>
>> What do you think?
>>
>> Cheers,
>> Priit
>>
>
>
>
> --
> Dr Nic Williams
> iPhone and Rails consultants - http://mocra.com
> Fun with iPhone/Ruby/Rails/Javascript - http://drnicwilliams.com
> * Surf Report for iPhone - http://mocra.com/projects/surfreport/ *
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---