Ruby on rails 3.2 在链接“”中使用*路径(:param=>;@param)不会将参数传递给控制器
这是我的设置:Rails 3.2.13 我已经为new传入了一个参数“restaurant_id”,现在正试图通过提交按钮为create传递相同的参数。但是,它似乎无法识别create的参数 对于新的:Ruby on rails 3.2 在链接“”中使用*路径(:param=>;@param)不会将参数传递给控制器,ruby-on-rails-3.2,Ruby On Rails 3.2,这是我的设置:Rails 3.2.13 我已经为new传入了一个参数“restaurant_id”,现在正试图通过提交按钮为create传递相同的参数。但是,它似乎无法识别create的参数 对于新的: <%= link_to t('.new', :default => t("helpers.links.new")), new_reservation_path(:restaurant_id => restaurant.id), :
<%= link_to t('.new', :default => t("helpers.links.new")),
new_reservation_path(:restaurant_id => restaurant.id),
:class => 'btn btn-primary' %>
当我在控制器中测试:restaurant_id时,它返回空白
奇怪的是,我使用了完全相同的方法将:restaurant_id传递给我的新控制器,但当我将其传递给我的create控制器时,它却不起作用。我看不到提交按钮的代码,但由于提交按钮发送表单,因此需要将参数作为隐藏字段传递(HTML表单的
操作
路径中后面的或.Arguments将无法通过。谢谢!我可以使用此选项通过它。
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
reservations_path(:restaurant_id => @restaurant.id), :class => 'btn' %>
class ReservationsController < ApplicationController
def new
@reservation = Restaurant.find(params[:restaurant_id]).reservations.new
@restaurant = Restaurant.find(params[:restaurant_id])
end
def create
@reservation = Restaurant.find(params[:restaurant_id]).reservations.new(params[:reservation])
if @reservation.save
redirect_to root_url, notice: 'Reservation was successfully created.'
else
render action: "new", notice: 'There was an error.'
end
end
end
ActiveRecord::RecordNotFound in ReservationsController#create
Couldn't find Restaurant without an ID