0

私のXMLエラー:

NoMethodError in Admin/xml#index

Showing C:/Rails/asdw/app/views/admin/xml/index.rhtml where line #1 raised:

undefined method `name' for "preview":String

Extracted source (around line #1):

1: <% update_xml("preview") %>
2: 
3: 
4: <h2>Preview/publish</h2>

私のコントローラー:

def index
    @photographer = Photographer.find(:first)
    #render :layout => false
end 

私の XML ヘルパー:

   module XmlHelper
        require 'builder'

            def update_xml(photographer, output="preview") 

                xml = Builder::XmlMarkup.new



                 xml.photographer(:name => photographer.name) do    



                  for group in photographer.groups 
                    xml.group(:name => group.name) do 
                    for project in group.projects 
                        xml.project(:name => project.name) do 
                                    for collection in project.collections
                                        xml.collection(:name => collection.name) do 
                                            for image in collection.images
                                                xml.image(image.description, :url => image.image, :id => image.id)


                                            end 
                                        end     
                                    end 
                        end 
                    end
                    end     
                  end       
                end           


                File.open("#{rails_root}/public/xml/#{output}.xml", "w") do |f|
                  f.puts ("#{xml}")
                end 


        end 






end

アップデート:

使用<% update_xml(photographer, "preview") %>:

NameError in Admin/xml#index

Showing C:/Rails/asdasd/app/views/admin/xml/index.rhtml where line #1 raised:

undefined local variable or method `photographer' for #<#<Class:0x47eb990>:0x47ea238>

新しい更新を使用して <% update_xml(@photographer, "preview") %>:

oMethodError in Admin/xml#index

Showing C:/Rails/asdfsadf/app/views/admin/xml/index.rhtml where line #1 raised:

undefined method `groups' for #<Photographer:0x45ca2d8>

Extracted source (around line #1):

1: <% update_xml(@photographer, "preview") %>
2: 
3: <h2>Preview/publish</h2>
4

2 に答える 2

2

Admin/xml#index で <% update_xml("preview") %> の代わりに "<% update_xml(photographer, "preview") %>" を使用してみてください。再度エラーが発生した場合はお知らせください。

于 2011-09-12T11:56:31.940 に答える
0

groupsPhotographer モデルに次のような関連付けがあることを確認してください。

has_many :groups
于 2011-09-12T12:38:32.297 に答える