我是Ruby on Rails的新手,正在完成教程http://edgeguides.rubyonrails.org/getting_started.html
我开始设置'文章'路线,并在运行'rake routes'时有以下路线:
'文章GET / articles /:id(。:format)文章#show'
所以,我看到有一个路径,/ articles /:id,它应该映射到文章#show。但是,当我点击url:/ articles / 1时,我收到以下错误:
“未知行动 在ArticlesController“
中找不到动作'1'我完全不确定这里发生了什么。 Show在我的articles_controller.rb中定义:
class ArticlesController < ApplicationController
def new
end
def create
@article = Article.new(params[:article])
@article.save
redirect_to @article
end
def show
@article = Article.find(params[:id])
end
def index
@articles = Article.all
end
private
def article_params
params.require(:article).permit(:title,:text)
end
end
谁有想法?
更新:添加了Routes.rb
RailsStarter::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
get ':controller(/:action(/:id))'
root :to => 'say#hello'
# Sample resource route (maps HTTP verbs to controller actions automatically):
resources :articles
end
答案 0 :(得分:1)
从routes.rb文件中删除get ':controller(/:action(/:id))'
您应该删除(或更新)根路由,因为say#hello
来自介绍课程。