You asked for it.

# app/controllers/tags_controller.rb

def index
    params[:sort] ||= "url_title"
    @direction = !params[:x] ? "ASC" : "DESC"
    @tags = Tag.find(:all, :order => "#{params[:sort]} [EMAIL PROTECTED]")
    render_common_index
end

# render_common_index => render :template => "common/index"

# app/views/common/index.haml

= render :partial => "documents/drafts" if @drafts and !@ drafts.empty?
- if collection.to_a.size > 5
  = render :partial => "common/commands"
= index_feedback
- if @category
  %p#scoped= "<label>Category:</label> #{link_to @category.title_html ,
{:action => :index}, :class => :category, :title => "Remove category
restriction and view all #{trollers}"}"
- if @tag
  %p#scoped= "<label>Tag:</label> #{link_to @tag.title_html , {:action =>
:index}, :class => :tag, :title => "Remove tag restriction and view all
#{trollers}"}"
= render_common_table
= render :partial => "common/commands"

# trollers is merely shorthand [defined in a helper] for
controller.controller_name.pluralize
# render_common_table => render :template => "common/table"

# app/views/common/table

- if action == "search" and !collection.empty?
  %p#results= pluralize( collection.size, "Result") + " for " +
content_tag(:span, params[:q])
%table
  - if collection.empty?
    - if action == "search"
      %tr
        %td.empty
          = "Sorry, we were unable to find any #{trollers} which match your
search terms: <span>#{params[:q]}</span>"
          - if @excluded
            %br/
            = "These terms were excluded from your search: <span>#{@
excluded.join(" ")}</span>"
          %br/
          Please try again, making sure your terms each have at least four
letters.
    - else
      %tr
        %td.empty= "You currently have no " + published? + trollers
  - else
    %thead
      = render :partial => "#{troller}_headers"
    %tbody
      = render :partial => troller, :collection => collection
      - if collection.respond_to?(:page_count) and collection.page_count > 1
        %tr.pagination
          %td{:colspan => troller == "entry" ? 7 : 6}= page_links

# troller is the singular of that trollers earlier.
# collection => controller.instance_variable_get("@#{trollers}")

# That render :partial => troller, :collection => collection is actually...
# render :partial => "tag", :collection => @tags
# which is where the tag reference screws up, I think.

All of this actuall comes out right. The _problem_ is that ones it compiles
this the first go-round, in my application.haml layout

!!! Strict
%html
  %head
    %title= "Oyster" + subtitle
    = javascript_include_tag :defaults
    = stylesheet_link_tag("oyster").downcase

That stylesheet_link_tag("oyster").downcase returns a member of the @tags
array. There's a call to the Rails method tag in there somewhere and because
the page has been compiled that first time tag is still showing up from the
render :partial => "tag", :collection => @tags which [I assume] is basically
a @ tags.each do |tag| and I've seen where that tag from the loop can stay
in or out of "scope" oddly before.

Does that clear it up? [Clear as mud, right?]

RSL


On 4/17/07, Nathan Weizenbaum <[EMAIL PROTECTED]> wrote:
>
>
> I'm not entirely sure what this is. What's the exact code you're using,
> the result you expect, and the result you're getting?
>
> - Nathan
>
> RSL wrote:
> > After a little [a lottle] more searching and mucking about, it looks
> > like the partial for _tag.haml might be the problem. It's creates that
> > variable tag and [if I understand things correctly] and the render/
> > delegation process is using it again when trying to render_file?
> > Maybe? I _hate_ the idea that I'm going to have to rename an entire
> > class or create some insane workaround for the partials process on
> > this one. Fingers crossed that there's a really simple way to solve
> > this.
> >
> > Please. :)
> >
> > RSL
> >
> > On Apr 17, 5:45 pm, "Russell Norris" <[EMAIL PROTECTED]> wrote:
> >
> >> I've got a model called Tag which is causing some strange problems with
> Haml
> >> on the index method of the TagsController
> >>
> >> @tags = Tag.find(:all)
> >>
> >> is somehow causing Haml to override the Rails tag helper/method with @
> >> tags.first from that Tag.find(:all). I removed Haml and everything went
> back
> >> to normal. As it is htuogh, stylesheet_link_tag("application") returns
> a Tag
> >> object and any other reference to tag does the same. Any ideas why?
> >>
> >> RSL
> >>
> >
> >
> > >
> >
> >
>
>
> >
>

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