Hi,
I'm new to rails and I'm building a small app. I have an album model
that can have many comments. Albums belong to families, laid out in
routes.rb. I want to be able to add comments in my /albums/
show.html.erb. I currently have this in the album controller:
def post_comment
@comment = Comment.new(params[:comment])
respond_to do |format|
if Comment.save
flash[:notice] = "Comment added"
format.html { redirect_to(@family, @album) }
end
end
end
and in the show.html.erb
<div id="comments">
<center>
<% if @album.has_comments? %>
<% for comment in @album.comments %>
<%= comment.user.login %> on <%= comment.created_at %>
<%=h comment.text %>
<% end %>
<% end %>
</center>
</div>
<%= link_to_function "Add another comment" do |page|
page.insert_html :bottom, :comments, :partial => 'comments' end %>
and the _comments.html.erb looks like:
<% form_for(:comment, :url => {:action => "post_comment"}) do |f| %>
...
<% end %>
routes.rb:
map.resources :families do |families|
families.resources :albums
end
The problem is that whenever I hit submit in the Albums show view, it
re-directs me to /albums/post_comment, which doesn't work because it
can't find a family.id - I would like to remain on the /family/id/
album/id page. Is there something else I need to do here because the
Album controller is a nested resource?
Thanks,
Ryan
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---