开发者

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 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜