Friday, May 6, 2011

Re: [Rails] Re: form_for, need to modify the :url based on if it is persisted or not

Thanks.

When you add something to a helper like articles_helper, does it have the request object in there also?

How does it get the @articles object when I call it like:

form_for @article, correct_post_path, ...

I would have though it would be:

form_for @article, correct_post_path(@article), ...




On Thu, May 5, 2011 at 4:02 PM, Eugen Ciur <lists@ruby-forum.com> wrote:
You can create a helper method (in helpers/articles_helper.rb):
 def correct_post_path
   @article.persisted? comment_article_path : articles_path
 end

And then use this helper in your form builder
 form_for @article, correct_post_path do ... end

That helps ? Maybe you can tell us under what conditions you need to
change post url, maybe you over-engineer somewhere...

----
http://blog.eugen.co

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate