how to structure this HAML code to not include some <div>

if the HAML is:

    .class1
      .class2
        .class3
          %div
            content... many lines

How can it be made so that it doesn't respond with class1 and class2 if
it is Ajax?

    - if !request.xhr?
      .class1
        .class2

    .class3
      %div
        content... many lines

won't work, because if not Ajax, then class3 is not a child of class2.
It might have to be something like

    - if !request.xhr?
      .class1
        .class2
          .class3
            %div
              content... many lines
    - else
      .class3
        %div
          content... many lines

and it is repeating a lot of code. Can it be structure within the same
file? Or the second part made into a partial?

winter heat wrote:

if the HAML is:

    .class1
      .class2
        .class3
          %div
            content... many lines

How can it be made so that it doesn't respond with class1 and class2 if
it is Ajax?

Well, it's not quite clear what you really want.

First of all, do you need to nest the divs at all? Remember that one
element can have multiple classes, so .class1.class2.class3 is possible.

If not, then can you extract the .class1 and .class2 into a layout?

    - if !request.xhr?
      .class1
        .class2

    .class3
      %div
        content... many lines

won't work, because if not Ajax, then class3 is not a child of class2.
It might have to be something like

    - if !request.xhr?
      .class1
        .class2
          .class3
            %div
              content... many lines
    - else
      .class3
        %div
          content... many lines

and it is repeating a lot of code. Can it be structure within the same
file?

Perhaps, but your view shouldn't be testing request.xhr? . That's a
terrible idea.

Or the second part made into a partial?

That's probably a better idea.

Best,

let's assume class1, 2, and 3, etc all have their functions, so we need
all of them.

the 3rd code piece is what we want: class 3 should be nested inside of
class2, which is what this question is all about.

why is using "request.xhr?" inside of a view not a good idea? if so,
you should only use it in controller and why?

[Please quote when replying. It makes the discussion easier to follow.]

winter heat wrote:

let's assume class1, 2, and 3, etc all have their functions, so we need
all of them.

But do you need them nested, or can they be on the same element?

the 3rd code piece is what we want: class 3 should be nested inside of
class2, which is what this question is all about.

why is using "request.xhr?" inside of a view not a good idea?

Because the view shouldn't know anything about the nature of the
request. The view should only know what the controller tells it.

if so,
you should only use it in controller and why?

Because according to Rails MVC design principles, views should be as
dumb as possible. The request object is really none of the view's
business -- all the view should do is display the data the controller
passes it.

Best,

Marnen Laibow-Koser wrote:

[Please quote when replying. It makes the discussion easier to follow.]

winter heat wrote:

let's assume class1, 2, and 3, etc all have their functions, so we need
all of them.

But do you need them nested, or can they be on the same element?

yes, they need to be nested, which is why it is a problem with the "if"
in the first place.