Three submits, one controller

I have a 'new' page with a submit for creating stories. On the 'show' page the submit allows a user to enter comments. I now want a 'edit' page for the stories with another submit for updates. I have used the 'create' and 'update' methods in the stories_controller on the 'new' and 'show' pages. What method can I use for the submit on the 'edit' page?

Use update again. There is no problem calling the same action from two views.

Colin

You can also just add another public method to the controller. For instance, instead of using StoryController.update for updating the comments, you could use something like StoryController.add_comment.

Paul Lynch wrote:

You can also just add another public method to the controller. For instance, instead of using StoryController.update for updating the comments, you could use something like StoryController.add_comment.

How does the submit know which one to use?

Neil Bye wrote:

Paul Lynch wrote:

You can also just add another public method to the controller. For instance, instead of using StoryController.update for updating the comments, you could use something like StoryController.add_comment.

Googled loads, still can't work it out?

What do you mean?

Colin

How does the submit know which one to use?

What do you mean?

Colin

I now want a 'edit'

page for the stories with another submit for updates. I have used the 'create' and 'update' methods in the stories_controller on the 'new' and 'show' pages. What method can I use for the submit on the 'edit' page?

So I have two submits and two method definitions. how can I make each submit relate to one of the differet methods.

Neil

Do you mean you have two submits in one form? You had not mentioned that before, or I missed it.

Colin

Colin Law wrote: .

Do you mean you have two submits in one form? You had not mentioned that before, or I missed it.

Colin

There are three separate forms on three pages but they all refer to the stories_controller.rb . In the controller I a 'create' method for the 'new' page The 'update' method is for comments submitted on the 'show' page. Now I want an 'edit' page with a submit. What method can I use and how does the submit on the edit page know how to use it.

Attachments: http://www.ruby-forum.com/attachment/4562/stories_controller.rb

Wrong attachment

Attachments: http://www.ruby-forum.com/attachment/4563/stories_controller.rb

You can specify the action in the form_for statement.

However, as I suggested earlier I would not use a separate action anyway. If you look at your code for update and add_comment you will see there is a lot of similarity. I would combine add_comment into update and test params[:comment] to see whether to add the comment or not.

Colin

Neil Bye wrote:

I have a 'new' page with a submit for creating stories. On the 'show' page the submit allows a user to enter comments. I now want a 'edit' page for the stories with another submit for updates. I have used the 'create' and 'update' methods in the stories_controller on the 'new' and 'show' pages. What method can I use for the submit on the 'edit' page?

you can have id for submit button then on form submission check the id of the submit button in javascript method and based on the submit mutton you can set the form action there and submit the form then.

A more conventional approach here might be to treat comments as nested resources, and have a Comments controller.

And if you substitute Story for Article in Ryan's example app in the railscast, it would appear to pretty much be the OPs problem.

Colin Law wrote:

You can specify the action in the form_for statement.

Thats all I wanted to know, but HOW ,I'm afraid I can't yet understand anything more complex.

Neil

I suggest you start by looking at the docs for form_for. If you look at http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html (which was the first hit googling for form_for) you will find the first example shows how to use the url option to specify an action.

Also have a look at the rails guides at http://guides.rubyonrails.org/. Start with Getting Started, work through them writing and trying out the code yourself. When you get to the one on Action View Form Helpers you will find another example on how to use the url option of form_for to specify an action.

Colin

Colin Law wrote: