【发布时间】:2019-10-17 23:16:54
【问题描述】:
我更愿意直接从控制器调用我的 JS 方法,但我收到以下 Rubocop 错误。
错误:
Metrics/AbcSize:创建的分配分支条件大小太大 高的。 [15.17/15]
控制器:
def create ...
def create
@profile = current_user.profiles.new(modified_profile_params)
respond_to do |format|
if @profile.save
format.html { redirect_to profiles_path }
format.js { render js: "Helpers.SearchForm.AfterSearchSubmit();" }
else
format.html { render action: "new" }
format.js {
render js:
"Helpers.Bootstrap.Modal.init(
'Title',
'message','ok',
'',
'#oldmodal',
Helpers.SearchForm.AfterSearchSubmit
);"
}
end
end
end
为了解决这个问题,我尝试了以下方法:
def limit_modal_javascript
{
render js:
"Helpers.Bootstrap.Modal.init(
'Title',
'message','ok',
'',
'#oldmodal',
Helpers.SearchForm.AfterSearchSubmit
);"
}
end
但是,我在运行时遇到以下错误:
语法错误,意外的 tLABEL,期待 do 或 '{' 或 '(' {render js:
【问题讨论】:
标签: controller ruby-on-rails-5.2 rubocop