我有這些控制器無法引用參數
class Checkout::PaymentsController < ApplicationController
before_action :params
def create
if Order.where(:date => params[:date]).present?
redirect_to reserva_path
end
end
def params
params.require(:Order).permit(:date)
end
end
class Products::ReservesController < ApplicationController
before_action :set_product, only: [:show]
def index
@products = Product.all
end
def show
@product = Product.find(params[:pr_id])
end
def set_product
@partner = Product.find(params[:pr_id])
end
端
和視圖(show.html.erb)
<div class="detail">
<h3><%= @product.name %></h3>
<p><%= @product.description %></p>
<h4>R$ <%= @product.price %></h4>
<h4>Escolha a data</h4>
<%= form_tag(checkout_payments_path) do%>
<%= hidden_field_tag :product_id, @product.id %>
<div class="data">
<%= date_select(:date, :date, start_year: 2017) %>
</div>
<%= submit_tag "Alugar", class: "btn btn-success"%>
<% end %>
show.html.erb將product_id和date_select的日期作爲參數發送給Checkout/Payment控制器,但是我收到錯誤,說不能引用控制器(返回是動作控制器參數的一個實例) 我做錯了什麼?
OBS:控制器在不同的命名空間
編輯:服務器日誌錯誤
Started POST "/checkout/payments" for ::1 at 2017-07-02 12:25:19 -0300
Processing by Checkout::PaymentsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"XJdLe2QQww6MvWQ+XWExHlkTAJ7EOD316nxXf8m2YC4HapWtKMb1ciscGZUUNzmCOCuIugsgShYiDj102AfEUg==", "product_id"=>"1", "dates"=>{"{:start_year=>2017}(3i)"=>"2", "{:start_year=>2017}(2i)"=>"7", "{:start_year=>2017}(1i)"=>"2017"}, "commit"=>"Alugar"}
Completed 500 Internal Server Error in 92ms (ActiveRecord: 4.0ms)
TypeError (can't quote ActionController::Parameters):
app/controllers/checkout/payments_controller.rb:4:in `create'
編輯2: 只見日期作爲哈希過去了,看到日誌
Processing by Checkout::PaymentsController#new as HTML
Parameters: {"utf8"=>"✓", "product_id"=>"1", "date"=>{"date"=>"201-01-08"}, "commit"=>"Alugar"}
Rendering checkout/payments/new.html.erb within layouts/application
Rendered checkout/payments/new.html.erb within layouts/application (0.0ms)
User Load (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 8 ORDER BY `users`.`id` ASC LIMIT 1
Rendered shared-templates/_header.html.erb (8.0ms) [cache miss]
Completed 200 OK in 356ms (Views: 324.7ms | ActiveRecord: 0.0ms)
我加入控制器:
def date_params
params.require(:date).permit(:date)
end
,但我仍然有這個vallue:
#<ActionController::Parameters:0x0000000d4d7c60>
什麼是確切的錯誤信息?請在服務器日誌 – Pavan
中生成的'params'發佈看看編輯,請 –