Rails : Can I use forms from the public/index.html file?
Am currently using R开发者_JAVA技巧ails 3.0 to develop my app.
How to handle a form in thepublic/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?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:
- Create a controller (i.e.,
home
viarails g controller Home index
) - Modify
routes.rb
and addroot :to=>"home#index"
- 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.
精彩评论