开发者

conflict with instance variables and local variables in partials

开发者 https://www.devze.com 2023-03-06 21:13 出处:网络
In one view I use render :partial => \"form_linktype_#{@linkjob.link_type}\", :locals => {:linkjob =>@linkjob }

In one view I use

render :partial => "form_linktype_#{@linkjob.link_type}", :locals => {:linkjob =>  @linkjob }

where @linkjob is an instance variable of type Linktype

In another view I use

render :partial => "shared/quality_requirements/linktype_#{o.link_type}", :locals => {:linkjob => o}

where o is a local variable of type Linktype. Both variables in both cases contain the same information. The only differe开发者_如何学Cnce is their scope.

Still, if I use

<b><%= linkjob.atext %></b>

in the partial, it renders beautifully for the second case but throws a

undefined local variable or method `linkjob' for #<#<Class:0xab61db8>:0xab5a964>

in the first case.

Is there a way to either turn a instance variable into a local variable or somehow else solve this problem?


You might try changing your first view to

render :partial => "form_linktype_#{@linkjob.link_type}", :locals => {:linkjob =>  @linkjob || nil}
0

精彩评论

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