I'm trying to check - if some (language) attribute is changed and if it is equal to some value I need to change it into other proper value.
Here is my code:
EDIT:
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
My form:
<%= 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"]) %>
And when I'm changing category - it changint language to default. How can I prevent this ?
Gives me error:
undefined method `updated?' for "--- please select ---":String
What I'm doing wrong ?