Ruby on Rails, Layout

<%= render :partial => "person" %>

the partial is named "person," the main template will look for an instance variable @person, and pass it to the partial as a local variable, person.if the instance variable doesn't match the name of the partial, you'd explicitly pass it, like this:

<%= render :partial => "person", :locals => { :person => @scott } %>
All the key/value pairs in the :locals hash will be made into local variables for the partial.

<%= render :partial => "person", :collection => @people %>
In this example, the main template has an array @people that will be looped through, passing a local variable person to the partial.

render :layout => false
def reverse
  @reversed_text = params[:text_to_reverse].reverse
  render :layout => false
end

此條目發表在 Ruby on Rails 分類目錄。將固定鏈接加入收藏夾。

發表評論