Ruby on Rails:/ articles /:id不匹配/ articles / 1

时间:2014-08-01 14:01:20

标签: ruby-on-rails

我是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

1 个答案:

答案 0 :(得分:1)

从routes.rb文件中删除get ':controller(/:action(/:id))'

您应该删除(或更新)根路由,因为say#hello来自介绍课程。

相关问题