# Submit redirection to incorrect URL

**URL:** <https://www.ruby-forum.com/t/submit-redirection-to-incorrect-url/149812>\
**Category:** Rails\
**Created:** [September 30, 2008, 4:33am UTC](https://www.ruby-forum.com/t/submit-redirection-to-incorrect-url/149812 "2008-09-30T04:33:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [September 30, 2008, 4:33am UTC](https://www.ruby-forum.com/t/submit-redirection-to-incorrect-url/149812/1 "2008-09-30T04:33:49Z")

</div>

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

\<% if @album.has\_comments? %\> \<% for comment in @album.comments %\> \<%= comment.user.login %\> on \<%= comment.created\_at %\> \<%=h comment.text %\> \<% end %\> \<% end %\>

\<%= 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

---

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [October 1, 2008, 1:51am UTC](https://www.ruby-forum.com/t/submit-redirection-to-incorrect-url/149812/2 "2008-10-01T01:51:19Z")

</div>

Still having trouble on this one - anyone have any ideas?

Here’s the log entry:

Processing AlbumsController#post\_comment (for 127.0.0.1 at 2008-09-30  
19:33:18) [POST]  
Session ID:  
BAh7CToMdXNlcl9pZGkGOg5yZXR1cm5fdG8iEC9mYW1pbGllcy8xOgxjc3Jm  
X2lkIiUxY2U3ODYyNjI4ZWJkMWY1MDdmOTI0NGRkYmRjNTFhNSIKZmxhc2hJ  
QzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVz  
ZWR7AA==–e3e9afa3685c8211fcda8482f58bfc32105cb627  
Parameters: {“commit”=\>“Submit”,  
“authenticity\_token”=\>“daf5fa075e733d5c8ac954d81b3304d783361e68”,  
“action”=\>“post\_comment”, “controller”=\>“albums”,  
“comment”=\>{“text”=\>“test”, “album\_id”=\>“1”, “user\_id”=\>“1”}}

ActiveRecord::RecordNotFound (Couldn’t find Family without an ID):

So, I believe that the action in the album controller is working  
correctly, since it is being processed, and all of the data is passing  
through correctly in the parameters, but it is still directing me back  
to /album/post\_comments instead of /families/id/albums/id - any ideas?

Thanks,  
Ryan
