Rails 4 - passing variable to partial

后端 未结 7 1430
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 03:49

I am following the Ruby on Rails tutorial and have come across a problem while trying to pass variables to partials.

My _user partial is as follows

7条回答
  •  感情败类
    2020-11-28 04:15

    You need the full render partial syntax if you are passing locals

    <%= render @users, :locals => {:size => 30} %>
    

    Becomes

    <%= render :partial => 'users', :collection => @users, :locals => {:size => 30} %>
    

    Or to use the new hash syntax

    <%= render partial: 'users', collection: @users, locals: {size: 30} %>
    

    Which I think is much more readable

提交回复
热议问题