我完成了一个表格并发送了它,但是由于一个奇怪的原因,它没有保存区域字段
1-视图
<div class="field">
<%= form.label :región %>
<%= select_tag(:region, options_for_select([['Lisbon', 'lisbon'], ['Madrid', 'madrid']]),:required => true, :include_blank => '-- Seleccione una Región --',id: :question_region) %>
</div>
2-
Started POST "/questions" for 127.0.0.1 at 2019-04-23 16:02:32 -0400
Processing by QuestionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"71bcceUQeh6esxxsU/9qPyjWWsNgOLZXuWOMWJ8JvwlQ7Mt6uY56as1WBTzyOtUKJBf/drsJBtYh1HSu+V3KTg==", "question"=>{"name"=>"marcelo", "email"=>"xxxx@gmail.com", "content"=>"Esto es un mensaje de prueba"}, "region"=>"lisbon", "commit"=>"Ingrese su pregunta"}
(0.3ms) BEGIN
SQL (3.3ms) INSERT INTO `questions` (`name`, `email`, `content`, `created_at`, `updated_at`) VALUES ('marcelo ', 'xxxx@gmail.com', 'Esto es un mensaje de prueba', '2019-04-23 20:02:32', '2019-04-23 20:02:32')
(1.6ms) COMMIT
Redirected to http://localhost:3000/questions/10
Completed 302 Found in 11ms (ActiveRecord: 5.2ms)
我该怎么做才能在“插入到”中包含区域
答案 0 :(得分:1)
如果region是Question模型的属性,则应使用form.select
而不是select_tag
,以便将该区域包括在问题的参数哈希中:
<%= form.label :región %> <%= form.select(:region, options_for_select([['Lisbon', 'lisbon'], ['Madrid', 'madrid']]), :required => true, :include_blank => '-- Seleccione una Región --', id: :question_region) %>