私のアプリケーションでは、ユーザーにストアを検索してから、使用するストアを選択してもらいたいと思います。ユーザーが記事へのコメントのようにそのストアに新しい価格を追加できるフォームに移動する必要がありますが、代わりにエラーが発生します。
ActiveRecord::RecordNotFound in PricesController#new
Couldn't find Store without an ID
これらは私の協会です:
class User
has_many :prices
class Store
has_many :prices
class Price
belongs_to :user
belongs_to :store
したがって、ユーザーがストアを選択するときは、price/new
使用されているストアのIDにアクセスして知る必要があります。多分次のようなものです:
<%= form_for @price, :url => create_price_store_path(@store) do |f| %>
...
<% end %>
次に、私が使用しているアクション:
class PricesController
def select_store
# Find the store using sunspot search
@search = Store.search do |s|
s.fulltext params[:search] unless params[:search].blank?
s.paginate(:per_page => 5, :page => params[:page])
end
@stores = @search.results
end
def new
@store = Store.find(params[:id])
@price = Price.new
end
end
それからこれまでの私のルート:
resources :stores do
member do
post :create_price
end
end
resources :prices do
collection do
get :select_store
end
end
なぜこのエラーが発生するのですか?何を修正する必要がありますか?