It's not always so cut and dry. Should I be creating a new helper for every 
complicated link_to statement in rails?

Here's one I picked out of a random project

= link_to "Favorites <em class='count_favorites'>#{count_favorites}</em>", 
"#"+resource(:users, :favorites), :class => "dropmenu_trigger", :rel => 
"#dropmenu_favorites"

Why should I force this to be on one line? And why should I create a helper 
just for a single link_to statement used once on the site?

On Nov 24, 2009, at 7:43 PM, Alexander Wallace wrote:

> This sounds more of an architectural problem than a markup problem. Argument 
> names for your helpers should (probably) be coming from your controllers - 
> e.g. = some_helper_function(@page, @section, @user) ... I'm not sure what the 
> necessity is to split arguments up into separate lines unless they are 
> strangely long (in which case they could just be shortened) or are actually 
> the return statements from other helpers (in which case it would be cleaner 
> to set those values in the controller)...
> 
> Alex
> 
> On Tue, Nov 24, 2009 at 10:37 PM, Nathan Weizenbaum <[email protected]> wrote:
> Even in this case, it ends up working better if you factor those out into 
> individual named helpers. "= get_new_posts_link" is a lot easier to 
> understand than a long helper with a lot of arguments, even if that's the 
> only place you use that helper.
> 
> 
> On Tue, Nov 24, 2009 at 7:31 PM, Jacques Crocker <[email protected]> wrote:
> If thats the case, can we at least make it easier to call helpers with lots 
> of arguments?
> 
> = some_long_helper_name arg1,
>                       arg2,
>                       arg3
> 
> 
> Comma + newlines are allowed when specifying attribute syntax. We should 
> allow it when calling helpers too.
> 
> In a large haml project, I often have helpers just to provide arguments to 
> other helpers. Ends up being pretty terrible sometimes
> 
> On Nov 24, 2009, at 5:44 PM, Nathan Weizenbaum wrote:
> 
>> The Haml multiline syntax is intentionally awkward. It's meant to encourage 
>> people away from putting large blocks of Ruby in their views, and towards 
>> moving their code into helpers. This almost always results in nicer code and 
>> easier-to-read views.
>> 
>> On Tue, Nov 24, 2009 at 10:15 AM, svoop <[email protected]> wrote:
>> Hi
>> 
>> How about allowing an alternative multiline syntax:
>> 
>> http://pastie.org/713107
>> 
>> Maybe this is a no go for the parser, though.
>> 
>> Cheers, -sven
>> 
>> --
>> 
>> 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.
>> 
>> 
>> 
>> 
>> --
>> 
>> 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.
> 
> 
> --
> 
> 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.
> 
> 
> --
> 
> 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.
> 
> 
> --
> 
> 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.

--

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.


Reply via email to