【问题标题】:Trouble with locals and partials with Rails使用 Rails 处理局部变量和局部变量的问题
【发布时间】:2011-11-03 10:51:51
【问题描述】:

我的 js.erb 文件中有以下内容:

$('#menu').after($("<%=escape_javascript(render 'boards/customize', :board => @board, :templates => @templates, :types => @types)%>") 

所以我尝试将一些本地人传递给我的部分

在我的 _customize.html.erb 中

<div id="customize">
          <ul id="categories">
            <% @types.each do |type|%>
            <li><%=link_to type.name, change_type_board_path(board, :type_id => type.id), :remote =>  true %></li>
            <% end %>
        </ul>
        <div id='carousel'>
            <%=render 'boards/carousel', :templates => templates %>
        </div>
    </div> 

I get the following error:

undefined local variable or methodboard' 代表#

你应该如何将这些变量传递给 Rails 中的局部变量?

【问题讨论】:

    标签: ruby-on-rails-3 partials


    【解决方案1】:

    在 Rails 3 中:

    render :partial => 'boards/customize', 
           :locals => { :board => @board , :templates => @templates, :types => @types }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 2016-08-23
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多