我安装了gem rails_best_practices,我想知道如何用局部变量替换我的实例变量?
我尝试过使用:locals => { :department_category => @department_category }
,但我不确定这是否是我的代码中甚至会出错的部分
问题行如下:
%a.black-link.bold{href: admin_content_departments_category_edit_path(params[:department_id], params[:child_department_id], category.id), :class => ("active" if @department_category.id == category.id)}
#{category.title}
为什么此代码会出错?
答案 0 :(得分:0)
用本地变量
替换实例变量
我相信您使用_category_edit.haml
呈现:locals => { :department_category => @department_category }
,然后您应该使用department_category
(本地变量)代替@department_category
(_category_edit.haml
#_category_edit.haml
%a.black-link.bold{href: admin_content_departments_category_edit_path(params[:department_id], params[:child_department_id], category.id), :class => ("active" if department_category.id == category.id)}
#{category.title}