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?
On 5 March 2010 20:33, Neil B. [email protected] 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?
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 L. 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 B. wrote:
Paul L. 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?
On 7 March 2010 13:49, Neil B. [email protected] wrote:
Paul L. 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?
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
Colin L. 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.
On 10 March 2010 12:13, Neil B. [email protected] wrote:
‘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.
Do you mean you have two submits in one form? You had not mentioned
that before, or I missed it.
Colin
On 10 March 2010 12:44, Neil B. [email protected] wrote:
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
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 B. 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.
Wrong attachment
On Wed, Mar 10, 2010 at 8:22 AM, Colin L. [email protected]
wrote:
‘new’ page
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.
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.
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Colin L. 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
On 10 March 2010 18:24, Neil B. [email protected] wrote:
Colin L. 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.
I suggest you start by looking at the docs for form_for. If you look
at ActionView::Helpers::FormHelper
(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 L. wrote:
On 10 March 2010 18:24, Neil B. [email protected] wrote:
I suggest you start by looking at the docs for form_for. If you look
at ActionView::Helpers::FormHelper
(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
Thanks very useful links. Will keep me busy.
Neil