views:

20

answers:

1

I'm a newbie to Rails. Am currently using Rails 3.0 to develop my app. How to handle a form in the public/index.html file which I'm planning to use as my Home page. Usually a view's action buttons gets paired with the corresponding method of its controller. But how to handle this in case the index file in public directory.

Thanks in Advance.

A: 

This is possible, so long as the form's action attribute is pointing at an action of a Rails controller. However, it is not the norm in Rails to use a static HTML page to capture data. The norm is to use the MVC architecture of Rails.

I have to ask: Have you read the documentation provided on the Ruby on Rails website? Check out http://edgeguides.rubyonrails.org and read the Getting Started section.

Now, I think you might be using public/index.html because you don't know how to use a controller to serve the root of your website. Here's a quick example of how to use a controller instead of public/index.html:

  1. Create a controller (i.e., home via rails g controller Home index)
  2. Modify routes.rb and add root :to=>"home#index"
  3. Delete public/index.html

The above is actually in the Edge Guides, Getting Stated section. So again, I strongly recommend you read the documentation. It will honestly save you a lot of trouble.

John