0
我試圖訪問我的Rails應用程序的「主頁」:3000 /家NoMethodError當我嘗試訪問本地主機:由去到localhost 3000 /家
當我嘗試上面的鏈接,但是,我得到下面的錯誤信息---但是這對我沒有意義,因爲'category'只是一個訂單的參數。訂單有一個類別,商店,項目和其他參數。
我的代碼如下。我在這裏做錯了什麼?
Showing /Users/fk/tenence_ai/app/views/tenence/home.html.erb where line #49 raised:
undefined method `category' for #<Order:0x007f8ed99c8500>
Extracted source (around line #49):
47 <div>
48 <%= form_for :order, url: orders_path do |f| %>
49 <%= f.text_field :category,:id=> 'category',:style=>'display:none' %>
訂單CONTROLLER
class OrdersController < ApplicationController
respond_to :html, :json
def show
@order = Order.find(params[:id])
@idx = Order.last.id
render json: @order
end
def create
@order = Order.new(order_params)
@order.save
end
def edit
@order = Order.find(params[:id])
end
def update
@order = Order.find(params[:id])
@order.update(order_params)
end
respond_to :html, :json
private
def order_params
params.require(:order).permit(:address,:store,:name,:items,:category,:status,:total,{:item => []},{:price => []})
end
end
ORDER MODEL
class Order < ApplicationRecord
end
RELEVANT MIGRATION
class CreateOrders < ActiveRecord::Migration[5.0]
def change
create_table :orders do |t|
t.string :name
t.text :address
t.string :store
t.text :items
t.timestamps
end
end
end
是否將「rails/rake routes」顯示爲列表路線? – zee
你有'category'欄目嗎?請也顯示你的遷移。謝謝! – araratan
@hikmatyar,查看下面的答案 – araratan