1
votes

I'm brand new to Ruby on Rails, and am working through the tutorial http://edgeguides.rubyonrails.org/getting_started.html

I started by setting up an 'articles' route, and have the following routes when running 'rake routes':

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

So, I see that there is a path, /articles/:id, which should map to articles#show. however, when I hit the url: /articles/1, I get the following error:

"Unknown action the action '1' could not be found in the ArticlesController"

I'm just not at all sure whats happening here. Show is defined in my 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

anyone have ideas?

Update: added 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
Could you also add your routes.rb file?Paweł Obrok
Your routes file is almost certainly out-of-order, e.g., you have a generic /:controller/:action matcher before your articles resource route.Dave Newton

1 Answers

1
votes

Remove the get ':controller(/:action(/:id))' from the routes.rb file

You should probably remove (or update) the root route as well, as say#hello is from the intro lesson.