winter heat
2010-Jul-30 08:56 UTC
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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jul-30 15:37 UTC
Re: how to structure this HAML code to not include some <div>
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, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
winter heat
2010-Jul-30 17:10 UTC
Re: how to structure this HAML code to not include some <div>
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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jul-30 19:06 UTC
Re: how to structure this HAML code to not include some <div>
[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 http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
winter heat
2010-Jul-30 19:37 UTC
Re: how to structure this HAML code to not include some <div>
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.