简体   繁体   中英

Ruby on Rails parameter not being saved on database

I have one form in views of controller customer_tasks that uses a dropdown menu with column names from model customer .
In the form, that dropdown menu is called with the following:

<div class="field">
  <%= f.label :search_column1 %><br>
  <%= select_tag :search_column1, options_for_select(Customer.translated_searchable_columns, params[:search_column1]), :include_blank => true %>
</div>

In my model customer the dropdown is generated with:

def self.searchable_columns
  wanted_columns = ['id', 'aa_code', 'name' ]
  self.column_names.select{ |column| wanted_columns.include?(column) }
end

def self.translated_searchable_columns
  columns = self.searchable_columns
  result = columns.map{ |column [Customer.human_attribute_name(column.to_sym), column] }
  result
end

In the customer_tasks controller I have the :search_column1 included on permitted parameters like:

def customer_task_params
  params.require(:customer_task).permit(:task_name, :period, :client_type, :search_column1, search_column1: [])
end

But the output of the development.log is:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"H4waTsM4D1+EZX+deFozJut6FRS36sVQe7d7a1oRK2w=", "customer_task"=>{"task_name"=>"blah", "period"=>"", "client_type"=>"Γ"}, "search_column1"=>"aa_code", "commit"=>"Ενημέρωση Customer task", "locale"=>"el", "id"=>"4"}

The dropdown is working and sending the chosen option. Why despite the fact that the parameter is permitted in the controller, it is not being saved/written to the database?

Why "search_column1"=>"aa_code" appears outside the parameters to the database?

What I am missing here?

You are using select_tag that's why "search_column1"=>"aa_code" appears outside the parameters to the database., if you use select it will go in the customer_task hash.

Change your select_tag to:

<%= f.select :search_column1, options_for_select(Customer.translated_searchable_columns, params[:search_column1]), :include_blank => true %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM