Hi, everybody:
I made a view - works as creating a new comment for a specific
article, a example URL is “http://localhost:3000/comments/new/2”:
here, comments is the controller, new is the action, 2 is the id of
the specific article, which needs to be passed to next action
“create”, so that this comment will be attached and displayed under
2nd article. However, I didnt figure out how I can pass the id to next
action named “create” in this controller, seems like only the
“comments” is the only parameter when I click the “create” button…
what can I do?
the new view as follow:
New comment
<%= error_messages_for :comment %>
<% form_for(@comment) do |f| %>
Desc
<%= f.text_area :desc %>
<%= f.submit "Create" %>
<% end %>
==================================
Thanks dudes!
Myst
Shortly I wanna deliver not only the “comments” but also the “id” as
params to next action.
myst_tt wrote:
Shortly I wanna deliver not only the “comments” but also the “id” as
params to next action.
Pass the id to the URL that the form posts to.
<% form_for @comment, :url => {:id => @comment} do |f| %>
good idea, RESTful… now I got to figure out how to do the nested
URL in route.rb, but anyway, thanks for your comments!
Br,
Myst
Why not change the URL completely? Have it as /posts/2/comments/new?
That
way form_for(@comment) should generate the proper URL for it.
On Jan 11, 2008 6:37 AM, Jeremy Weiskotten
[email protected]
wrote:
–
Ryan B.
Feel free to add me to MSN and/or GTalk as this email.
map.resources :posts, :has_many => :comments
or if you’re not using Rails 2.0
map.resources :posts do |post|
post.resources :comments
end
On Jan 11, 2008 7:24 AM, myst_tt [email protected] wrote:
way form_for(@comment) should generate the proper URL for it.
–
Ryan B.
Feel free to add me to MSN and/or GTalk as this email.