我有一个餐厅,购物车和用户模型.我想在进入餐厅时被重定向到购物车形式.此表格将询问我一个表号,然后为当前用户创建一个购物车.但是,在提交表单时,我遇到了传递参数的问题
Couldn't find Restaurant with 'id'=
Run Code Online (Sandbox Code Playgroud)
我想他们不在白名单中,但我找不到如何允许他们......我会感激任何建议!
通过的参数:
{"utf8"=>"?",
"authenticity_token"=>"*****",
"cart"=>{"restaurant_id"=>"1",
"table_id"=>"4"},
"commit"=>"Create Cart",
"user_id"=>"1"}
Run Code Online (Sandbox Code Playgroud)
我正在传递带有隐藏字段的restaurant_id和带有输入的表格
<%= f.hidden_field :restaurant_id, value: params[:restaurant_id] %>
<%= f.input :table_id %>
Run Code Online (Sandbox Code Playgroud)
在购物车控制器中:
def create
@restaurant = Restaurant.find(params[:restaurant_id])
@table = @restaurant.tables.find(params[:table_id])
@cart = current_user.carts.new(cart_params)
...
end
....
def cart_params
params.require(:cart).permit(:restaurant_id, :table_id)
end
Run Code Online (Sandbox Code Playgroud) 我发现了几个关于同一主题的问题,但它们都有标点符号问题(遗漏或添加了逗号)。就我而言,迁移时出现以下错误
SyntaxError: /home/ /workspace/ /app/models/user.rb:27: 语法错误,意外的 tSYMBEG,期望 keyword_do 或 '{' 或 '('
has_many :roles, through :positions
用户模型:
class User < ActiveRecord::Base
has_many :positions
has_many :roles, through :positions
end
Run Code Online (Sandbox Code Playgroud)
榜样:
class Role < ActiveRecord::Base
has_many :positions
has_many :users, through :positions
end
Run Code Online (Sandbox Code Playgroud)
岗位模型:
class Position < ActiveRecord::Base
belongs_to :role
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
知道可能是什么问题吗?谢谢!
这个简单的网站有问题。仅在移动版 chrome 浏览器上,导航栏的宽度大于主体的宽度。我寻找了某些元素的固定宽度,因为这解决了具有相同问题但找不到的帖子的问题...谢谢您的任何建议..