我正在尝试检查-是否更改了某些(语言)属性,并且是否等于某个值,我需要将其更改为其他适当的值。
这是我的代码:
编辑:
def update
@website = Website.find(params[:id])
@website.language = params[:website][:language]
if @website.language_changed?
if params[:website][:language] == "Automatic (by user's browser language)"
@website.language = full_language(request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first)
end
end
respond_to do |format|
if @website.save
format.html { redirect_to @website,
notice: 'Note: code has been updated. Please replace the code you have on your website with the code below. Only then changes will take effect.' }
end
end
end
我的表格:
<%= f.label "Website category"%>
<%= f.select :category, options_for_select([
"--- please select ---",
"Banking",
"Computers]) %>
<%= f.label "Language preferences"%>
<%= f.select :language, options_for_select([
"--- please select ---",
"Automatic (by user's browser language)",
"Arabic",
"Chinese"]) %>
当我更改类别时 - 它会将语言更改为默认值。我怎样才能防止这种情况?
给我错误:
undefined method `updated?' for "--- please select ---":String
我做错了什么?