Rails XML 未定义方法“名称”对于“预览”:字符串

发布于 2024-12-04 14:55:01 字数 2557 浏览 0 评论 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(摄影师,“预览”)%&gt;

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,“预览”)%>

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>

My XML error:

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>

My controller:

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

My XML helper:

   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:

Using <% 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>

NEW UPDATE Using <% 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

动听の歌 2024-12-11 14:55:01

您可以尝试使用“<% update_xml(photographer, "preview") %>”而不是 <% update_xml("preview") %>在 Admin/xml#index 中,如果再次出现错误,请告诉我!

Could you please try using "<% update_xml(photographer, "preview") %>" instead of <% update_xml("preview") %> in Admin/xml#index, let me know if you get error again!

客…行舟 2024-12-11 14:55:01

确保在您的 Photographer 模型中具有 groups 关联,例如:

has_many :groups

Make sure in your Photographer model you have a groups association such as:

has_many :groups
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文