【发布时间】:2014-09-24 18:17:39
【问题描述】:
我是 Ruby on Rails 的新手,正在学习教程http://edgeguides.rubyonrails.org/getting_started.html
我从设置“文章”路由开始,在运行“rake 路由”时有以下路由:
'文章 GET /articles/:id (.:format) 文章#show'
所以,我看到有一个路径 /articles/:id,它应该映射到articles#show。但是,当我点击 url:/articles/1 时,我收到以下错误:
“未知动作 在 ArticlesController 中找不到操作“1””
我只是不确定这里发生了什么。显示在我的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
【问题讨论】:
-
您能否也添加您的
routes.rb文件? -
您的路由文件几乎可以肯定是乱序的,例如,您的文章资源路由之前有一个通用的
/:controller/:action匹配器。
标签: ruby-on-rails