开发者

Trouble passing locals in Partial

开发者 https://www.devze.com 2023-02-12 18:38 出处:网络
I have a partial called _avatar.html.erb I want to pass in an id as a local variable called entity_id which will be the id of an object.

I have a partial called _avatar.html.erb I want to pass in an id as a local variable called entity_id which will be the id of an object.

<% form_tag({:controller => "avatar", :action => "upload", :id => entity_id},
     :multipart => true ) do %>
    <fieldset>
      <legend><%= title %></legend>
      <% if avatar.exists? %>
      <%= avatar_tag(avatar) %>
      [<%= link_to "delete", {:controller => "avatar",:action => "delete", 
           :id => entity_id},:confirm => "Are you sure" %>]
     ...

Here is the call for the parital:

<%= render :partial => 'avatar/avatar', :locals => {:avatar => @avatar, 
    :title => @title, :entity_id => @board.id } %>

When I try this I get the following errors:

undefined local variable or method `entity_id' for #<ActionView::Base:0x2736bb0开发者_JAVA技巧>

When I take that out I also get an error telling me it can't find the local variable "title".

Can anyone help this seems to be the correct way to do this.

Thanks in advance


Try using :id=>@entity_id (note the @ symbol preceding the name). Likewise, @title, instead of "title".

0

精彩评论

暂无评论...
验证码 换一张
取 消