我是rails的新手,我在销售网站遇到麻烦,我有一个用户和产品用户所属的protuto,一切正常,exeto编辑产品的动作。
产品中的ActionController :: UrlGenerationError#edit
没有路由匹配{:action =>“show”,:controller =>“products”,:format => nil,:id => nil,:user_id =>#}缺少必需的密钥: [:ID]
my_edit
<h1>Editing product</h1>
<%= render 'form' %>
<%= link_to 'Show', @product %> |
<%= link_to 'Back', products_path %>
my _form
<%= form_for [:user,@product], :html => {multipart: true} do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :price %><br>
<%= f.text_field :price %>
</div>
<div class="field">
<%= f.label :local %><br>
<%= f.text_field :local %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :category_id %><br>
<%= f.select :category_id, Category.all.map {|c| [c.name, c.id]} %>
</div>
<div class="field">
<%= f.label :contacts %><br>
<%= f.text_field :contacts %>
</div>
<div class="field">
<%= f.label :image %><br>
<%= f.file_field :image %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
my rake routes
Prefix Verb URI Pattern Controller#Action
sessions_new GET /sessions/new(.:format) sessions#new
category_category GET /categories/:id/category(.:format) categories#category
categories GET /categories(.:format) categories#index
POST /categories(.:format) categories#create
new_category GET /categories/new(.:format) categories#new
edit_category GET /categories/:id/edit(.:format) categories#edit
category GET /categories/:id(.:format) categories#show
PATCH /categories/:id(.:format) categories#update
PUT /categories/:id(.:format) categories#update
DELETE /categories/:id(.:format) categories#destroy
home_index GET /home(.:format) home#index
POST /home(.:format) home#create
new_home GET /home/new(.:format) home#new
edit_home GET /home/:id/edit(.:format) home#edit
home GET /home/:id(.:format) home#show
PATCH /home/:id(.:format) home#update
PUT /home/:id(.:format) home#update
DELETE /home/:id(.:format) home#destroy
profile_user GET /users/:id/profile(.:format) users#profile
user_products GET /users/:user_id/products(.:format) products#index
POST /users/:user_id/products(.:format) products#create
new_user_product GET /users/:user_id/products/new(.:format) products#new
edit_user_product GET /users/:user_id/products/:id/edit(.:format) products#edit
user_product GET /users/:user_id/products/:id(.:format) products#show
PATCH /users/:user_id/products/:id(.:format) products#update
PUT /users/:user_id/products/:id(.:format) products#update
DELETE /users/:user_id/products/:id(.:format) products#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
login GET /login(.:format) sessions#new
logout GET /logout(.:format) sessions#destroy
root GET / home#index
答案 0 :(得分:0)
根据您的评论,我发现您缺少传递产品的ID。
您需要通过@user
&amp; @product
这样的对象:
<%= link_to 'Edit', edit_user_product_path(@user, @product) %>