2017-08-05 150 views
0

我收到此错误。没有路线匹配{:action =>“show”,:controller =>“statics”},缺少必需的键:[:id]

enter image description here

<%= 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 

这是该项目的耙路线。

+0

我让你提出这些变化,但其不接受statics_path时,提示static_path。@ widjajayd –

+0

我只是改变我的回答对按照您的要求 – widjajayd

回答

0

与导轨不同软件点点的方式 或许这可以帮助,如果你不希望使用不同的模型与控制器名称

改变你的routes.rb如下

resources :products, path: "statics" 
+0

广东话我直接到静态控制器的路径。@ widjajayd –

+0

我为打扰你感到难过,但我仍然坚持同样的错误要么。 –

+0

好吧请改变你的routes.rb后请重新启动rails服务器命令 – widjajayd

相关问题