开发者

conflict with instance variables and local variables in partials

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜