On Wed, Jun 17, 2009 at 12:15 PM, Adam Hooper <[email protected]> wrote:

>
> On Wed, Jun 17, 2009 at 11:36 AM, Nicholas Van
> Weerdenburg<[email protected]> wrote:
> > I created the following helper:
> >   def xhr_form_for *args, &block
> >     if request.xhr?
> >       remote_form_for *args, &block
> >     else
> >       form_for *args, &block
> >     end
> >   end
> > To allow dynamic selection of form type based on whether the page is an
> AJAX
> > request or not.
> > Is there a way to do this outside of a helper? Not that I wish to do evil
> > and break any rules, but I'm curious for my understanding of HAML.
>
> Personally, I don't see this problem in my code, because:
> - I never use remote_form_for, since unobtrusive JS works even better
> - Usually my forms are in a separate partial (e.g.,
> "app/views/articles/_form.html.haml") so there's not much to indent
> anyway.
>
> Neither is a reason for you to remove your helper; I just thought I'd
> point out my general observation that indenting issues such as this
> one do not cause many problems in the context of what I consider to be
> programming best-practices.
>
> (Incidentally, your helper makes ERB code much cleaner: if you used it
> in ERB, you still wouldn't need icky indentation tricks.)
>
> > The above may not work because of the block, but a similar case
> > is:
> > -if color==:blue
> >   .blue_div
> > -else
> >    .red_div
> > Is there a way to indent under the red div without using a helper?
>
> This is a very common situation:
>
> %div{:class => (color == :blue ? 'blue_div' : 'red_div')}
>
> IMO the one-line syntax is better: it keeps the document structure
> perfectly clear. (You can throw in helpers or local variables to
> improve the legibility of that one line.)
>
> Adam
>
> --
> My Website: http://adamhooper.com
> My Blog: http://adamhooper.com/blog
>
> >
>
I agree in general- I've had almost no issues with HAML impacting my
development flow.

My form is in a partial. I decided to use it for both regular and AJAX
requests, hence the logic.

So, in short, there is no way to split conditionals in HAML, but rather you
store it on a single line. I agree that it's generally bad practice, but
sometimes I like prototype quickly within my view and then move  elsewhere.
However, it rarely happens so it's no big deal.

I'm curious on one comment:
 "I never use remote_form_for, since unobtrusive JS works even better"

Why do you find that? I assume you without the block form helpers as well in
that case? Sounds like more work that way.

Thanks,
Nick

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