Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails view without a controller

Can rails handle creating a view without a controller? For example, let say I have a page that just links to other pages, would I need to create a dummy controller for that, or could I just do something in my routes file?

like image 866
Daniel Avatar asked Aug 29 '09 21:08

Daniel


3 Answers

I like August's answer but I have a slightly different method.

Let's say you want to add

/any/path/somefile.html.erb

but not add a controller...

You can just add folder to views called "application", create your file in that directory..

Then in your routes file just add

match '/any/path/somefile' => 'application#somefile'

Your erb still evaluates, you get your layout, and you can create any path you want... (all this does is remove the need for the pages controller)

Hope it helps...

like image 103
Ben Miller Avatar answered Nov 11 '22 04:11

Ben Miller


No. All requests has to go through a controller.

I like to have a PagesController, with map.page ":action", :controller => "pages". That way, I can create app/views/pages/foo.erb and have it available on /foo without any extra code.

like image 16
August Lilleaas Avatar answered Nov 11 '22 05:11

August Lilleaas


Another option would be adding a static html file in your /public directory if you truly don't need it as part of your application.

like image 4
Andy Gaskell Avatar answered Nov 11 '22 03:11

Andy Gaskell