Rake route Error "Missing :action key on routes definition"
Solution 1
The Rails router recognizes URLs and dispatches them to a controller's action. The error is caused by missing out the mapped action.
Rails.application.routes.draw do
# url action
get 'script/index' => 'script#index'
get 'landing/index' => 'landing#index'
root 'script#index'
end
Solution 2
You can do it many ways, these all work:
- get 'script/index'
- get 'script/index' => 'script#index'
- get 'script/index', to: 'script#index'
Think of path first and controller#method to follow.
Root is a special case, always: root 'script#index'
Solution 3
Change
root 'landing/index'
to
root 'landing#index'
Solution 4
I had the same error running rails g
.
If you run a command that uses routes.rb
, the file needs to be error free for the command to work.
In your case, you had paths, but you didn't match them to actions, so the routes.rb
file was broken. You needed something like get 'landing/index' => 'my_controller#my_action'
Related videos on Youtube
Tithos
I am a talented, dedicated Front End Developer who loves what he does. I have a lot of fun creating and developing great things on the web. Much of my experience is in building static websites, but in the past 6 years, I have been branching out into web application development with JS (ES6) and React. I am looking for a role in my current skill set where I can thrive and make inspired, reliable contributions to my company or client codebase. I am also very excited to challenge myself and learn new things. On my own time, I enjoy learning and experimenting with new technologies and web disciplines. I have been getting my feet wet in React and Next.js and have built several personal apps. I am an intelligent, loyal, hard-working employee who is a kind, caring person. I know when to be serious and diligent in my work and at the same time, I have a joyous, albeit unique sense of humor and like having fun both at work and in private life. I am looking for a fulfilling remote job that will, in turn, allow me to live a life I take pleasure in.
Updated on July 09, 2022Comments
-
Tithos almost 2 years
I am getting
$ rake routes rake aborted! ArgumentError: Missing :action key on routes definition, please check your routes. /usr/local/rvm/gems/ruby-2.1.2/gems/actionpack-4.1.5/lib/action_dispatch/routing/mapper.rb:243:in `default_controller_and_action' /usr/local/rvm/gems/ruby-2.1.2/gems/actionpack-4.1.5/lib/action_dispatch/routing/mapper.rb:117:in `normalize_options!' /usr/local/rvm/gems/ruby-2.1.2/gems/actionpack-4.1.5/lib/action_dispatch/routing/mapper.rb:65:in `initialize' /usr/local/rvm/gems/ruby-2.1.2/gems/actionpack-4.1.5/lib/action_dispatch/routing/mapper.rb:1487:in `new' /usr/local/r................
Here is my Routes.rb
Rails.application.routes.draw do get 'script/index' get 'landing/index' root 'landing/index' end
What is causing the problem and how do I fix it.
-
tfantina over 7 yearsBasically your defining both how the root will look (left) and how rails will actually find it (right).
-
Beauty almost 7 yearsImportant: Use # symbol at the right side. (This was the error reason in my case.)
-
Alexis over 6 years9 years programming in rails and somehow I missed this lol, thanks