Recent Posts

November 2009
M T W T F S S
« Oct   Dec »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Mobile Barcode Tool

This is a 2D-barcode containing the address of our mobile site.If your mobile has a barcode reader, simply snap this bar code with the camera and launch the site.

Rails – simple problems

NOTE – I’m simply writing about what I find as I explore Ruby on Rails (ROR) – your mileage should vary but chances are you landed here due to a long tail search. Since I am not a Ruby or ROR expert it is quite possible for me to discover a solution or approach that works for me but which may not be a good Ruby/ROR solution.  Caveat Emptor!

Rails Routes

  • routes connect resources via controllers — :controller/:action/:id
  • if you have a static resource (i.e. a ‘view’) that does not have a controller you may have routing issues unless you use regular routing (explicitly defined routes)
  • Rails uses restful routing (via CRUD) so sometimes you have to create explicit connections - a detailed discussion on Rails routing is found here.
  • Rails routes use FEUF (first encountered = use first – so place explicit routes at the top of the file with any catch-alls or defaults at the bottom)

Duplicating the problem – Steps:

  1. rails myproject
  2. cd myproject
  3. script/generate controller Site help about index
  4. rm public/index.html
  5. script/server
  6. surf to the default URL for your Rails project (i.e. http://localhost:3000/)

Note that I am using Aptana RadRails which contains features where I ran the ‘generate’ command from within the very nice GUI (lots of features - great tool.)  Using RadRails I also start/stop the server and there is even a built-in browser view.

Rails Error Message:

Unknown action

No action responded to show. Actions: about, help, and index

In this case both the ‘about’ and ‘help’ Actions were not located, i.e. access the URL http://localhost:3003/site/help results in the error above.  They are only present as views (no controllers) but they are part of the ’site’ (there is a site controller and there are views for about and help under the ’site’ views folder.)

When the ’site’ resource was created the entry in routes.rb was:

map.resources :site

which did not work.  To get these resources working the route was changed to:

map.root :controller => “site” (default route) OR

map.connect ”, :controller => “site”, :action => “index” (empty route)

and now all works as expected.  Note that this change sets the default route (the root route) the the entire Rails site.  Note that a default route “makes every action of every controller in your application accessible to GET requests” - which may NOT be what you want…

An interesting side effect – if I add a route for ‘help’ then ‘about’ begins working as well – hmm.

map.help ‘help’, :controller => ’site’, :action => ‘help’

and the URL becomes: http://localhost:3003/help while about only works with: http://localhost:3003/site/about and ‘/’ no longer works…

A bit more – you can glean a bit more by using the command rake routes OR by running the Rails Console – script/console – which starts up an instance of IRB.

>> my_routes = ActionController::Routing::Routes (lots of data scrolls by after you press  RETURN)

and then request a listing of routes using puts (output will vary) – in this case I have one controller (site) and my defined route (from routes.rb) includes map.resources :site as well as the two defaults at the end of the file:

>> puts my_routes.routes
GET    /site(.:format)?                         {:controller=>"site", :action=>"index"}
POST   /site(.:format)?                         {:controller=>"site", :action=>"create"}
GET    /site/new(.:format)?                     {:controller=>"site", :action=>"new"}
GET    /site/:id/edit(.:format)?                {:controller=>"site", :action=>"edit"}
GET    /site/:id(.:format)?                     {:controller=>"site", :action=>"show"}
PUT    /site/:id(.:format)?                     {:controller=>"site", :action=>"update"}
DELETE /site/:id(.:format)?                     {:controller=>"site", :action=>"destroy"}

ANY    /:controller/:action/:id/                {}
ANY    /:con

When I change to the map.root route then the first line becomes:

ANY    /                                        {:controller=>"site", :action=>"index"}

and everything else is the same.  If I use the named route for ‘help’ then the first line of my routes becomes:

ANY    /help/                                   {:controller=>"site", :action=>"help"}

Share and Enjoy:
  • LinkedIn
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Blogosphere News
  • Technorati
  • TwitThis
  • Live
  • Slashdot
  • Sphinn
  • Mixx
  • Yahoo! Buzz
  • StumbleUpon
  • Facebook
  • MSN Reporter
  • Reddit
  • RSS
  • Yahoo! Bookmarks

Related posts:

  1. Rails – where is the missing stuff? ROR (Ruby on Rails) is advertised as a data-centric development...
  2. CMS Made Simple – 1st impressions Made Simple? Let's see how long it takes before the...
  3. Fedora 10 install problems Could just be me… Could just be luck of the...
  4. Zena – Rails CMS & VDI Playground CMS=Content Management System Rails = Ruby on Rails – a...
  5. Blog software: First set of problems… Site performance is Ok, but seems a bit slow...

Leave a Reply - Please use your Real Name...

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>