简体   繁体   中英

Rails routing not working for case sensitive URLs

After generating Pages Controller with this command -

>rails g controller Pages Home About Contact

and un comment the line match ':controller(/:action(/:id))(.:format)' at routes.rb File.

when I was accessing my URL like -

http://localhost:3000/pages/home

It throws error

Unknown action

The action 'home' could not be found for PagesController

However this was working if accessed like this -

http://localhost:3000/pages/Home

Small/Up case was my first thought so I installed route_downcaser as suggested HERE

Now the problem is both URLs are throwing same error -

http://localhost:3000/pages/home
http://localhost:3000/pages/Home

ERROR

Unknown action

The action 'home' could not be found for PagesController

Let me know how can I solve this error.

My project at Github - Github URL

Using Windows 7

Rails version - 3.2.9

EDIT

routes.rb file - 

Addbootstrap::Application.routes.draw do
  get "pages/Home"

  get "pages/About"

  get "pages/Contact"

  get "pages/Drop_Down"

  match ':controller(/:action(/:id))(.:format)'
end

In ruby you do not want to use upcased method names. Names starting with upcase letters are reserved for constants (classes/modules).

Aside from that, if you are using a gem that downcases your route from Home to home, and the method is named Home, then that is why it will fail. Make sure the method names are downcased.


In case anyone is going to point this out, I'll preempt. CapsCase method names are valid in ruby, they are just not conventional, and may be confusing. As such are considered a BadIdea. The only really special thing about CapsCase names is when they are assigned a value, ruby will raise warnings if you try to assign it again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM