我收到此錯誤。沒有路線匹配{:action =>「show」,:controller =>「statics」},缺少必需的鍵:[:id]
<%= link_to "New Product",
new_static_path %>
靜力學控制器
class StaticsController < ApplicationController
def index
@products = Product.all
end
def new
@product = Product.new
end
def show
product_value = Product.find(params[:id])
@product_attribute = ProductAttribute.where(value: product_value.value)
end
def create
@product = Product.new(product_params)
if @product.save
redirect_to root_url
else
render 'new'
end
end
def edit
@product = Product.find(params[:id])
end
def update
@product = Product.find(params[:id])
if @product.update(product_params)
redirect_to root_url
else
render 'edit'
end
end
def destroy
Product.find(params[:id]).destroy
flash[:success] = "Profile Updated"
redirect_to root_url
end
private
def product_params
params.require(:product).permit(:name,:value)
end
端
Index.html.erb<h1>Listing the products in home page</h1>
<% @products.each do |product| %>
<li><%=link_to product.name, static_path(product) %></li>
<li><%=link_to "Edit", edit_static_path(product) %></li>
<% end %>
的routes.rb 條
root 'statics#index'
resources :statics
resources :products
resources :productattributes
耙路線
Prefix Verb URI Pattern Controller#Action
root GET / statics#index
statics GET /statics(.:format) statics#index
POST /statics(.:format) statics#create
new_static GET /statics/new(.:format) statics#new
edit_static GET /statics/:id/edit(.:format) statics#edit
static GET /statics/:id(.:format) statics#show
PATCH /statics/:id(.:format) statics#update
PUT /statics/:id(.:format) statics#update
DELETE /statics/:id(.:format) statics#destroy
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PATCH /products/:id(.:format) products#update
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
productattributes GET /productattributes(.:format) productattributes#index
POST /productattributes(.:format) productattributes#create
new_productattribute GET /productattributes/new(.:format) productattributes#new
edit_productattribute GET /productattributes/:id/edit(.:format) productattributes#edit
productattribute GET /productattributes/:id(.:format) productattributes#show
PATCH /productattributes/:id(.:format) productattributes#update
PUT /productattributes/:id(.:format) productattributes#update
DELETE /productattributes/:id(.:format) productattributes#destroy
這是該項目的耙路線。
我讓你提出這些變化,但其不接受statics_path時,提示static_path。@ widjajayd –
我只是改變我的回答對按照您的要求 – widjajayd