Ruby on Rails: /articles/:id not matching /articles/1



我是Ruby on Rails的新手,正在学习教程http://edgeguides.rubyonrails.org/getting_started.html

我首先设置了一个'articles'路由,并且在运行'rake routes'时有以下路由:

'article GET/articles/:id (.:format) articles#show'

所以,我看到有一个路径,/articles/:id,它应该映射到article# show。然而,当我点击url:/articles/1时,我得到以下错误:

"未知的行动

在文章控制器 中找不到动作'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

从路由中移除get ':controller(/:action(/:id))'。rb文件

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

相关内容

最新更新