【发布时间】:2017-11-29 19:40:37
【问题描述】:
Rails 版本 5.1.4
你好,
我无法将我的 simple_form_for 的字段值 immo_type 保存到我的控制器 Pages
#app\controllers\pages_controller.rb
class PagesController < ApplicationController
skip_before_action :configure_permitted_parameters, only: [:home]
def home
@purchase = Purchase.new
@immo_type = params[:immo_type]
end
end
观点:
#app\views\pages\home.html.erb
<%= simple_form_for @purchase, url: purchases_path(@purchase), :method => :post do |f| %>
<%= f.input :address %>
<%= f.input :immo_type %>
<%= f.button :submit, "Search" %>
型号:
#app\models\purchase.rb
class Purchase < ApplicationRecord
belongs_to :user
has_many :users, :through => :searches
end
对不起,我是 ruby on rails 的新手!!!
我尝试在我的 Pages 控制器中输入 <%= debug params %> 或“raise”。我有这条消息
--- !ruby/object:ActionController::Parameters 参数:!ruby/hash:ActiveSupport::HashWithIndifferentAccess 控制器:pages 行动:允许回家:假
你能帮帮我吗?
【问题讨论】:
-
应该有一个创建动作来保存表单数据
-
Purchase 和 Immo_Type 有关系吗?
-
immo_type 属于购买Tab 作为地址
标签: ruby-on-rails strong-parameters simple-form-for