【问题标题】:Rails 4 : rendering collection in partial with another nameRails 4:使用另一个名称部分呈现集合
【发布时间】:2014-10-07 17:45:46
【问题描述】:

我尝试使用另一个部分名称来呈现一个集合

在我的 users_controller#index 中,标准列表带有标准 html 请求, 对应视图 users/index.html.ham 和部分 _user.html.haml

我正在尝试以不同的方式呈现 Ajax 请求上的用户列表,使用不同的部分

index.js.erb
.... 
$(content).html('<%= j render ("album_owner_index", @collection =>  @users, as: album_owner) %>');

但这不起作用,语法错误,意外',',期望')' # 在收集之前

如果我只写

$(content).html('<%= j render("album_owners_index") %>');

然后它使用标准的 _user.html.haml...
无论如何要改变它?

【问题讨论】:

    标签: ruby-on-rails-4 collections render


    【解决方案1】:

    我必须先在 index.ejs.erb 中使用

      $(content).html('<%= j render("album_owners_index") %>');
    

    然后在部分 _album_owners_index.html.haml 中,我必须渲染 @users 集合,使用 as: 参数 ... 以使用另一个部分而不是 _user :

      = render :partial => "backoffice/users/album_owner", :collection => @users, as: :album_owner
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多