Hello, I’m going through my latest addition Simply Rails 2.
The book is amazing and all, but certain adjustments had to be done along the way since it’s still Rails 2 for the look of it, and I’m all about doing it in the latest way-Rails 3
I’m having trouble with the code for the vote form:
<div id="vote_form">
<% form_remote_tag :url => story_votes_path(@story) do %>
<%= submit_tag 'shove it' %>
<% end %>
</div>
The code above it’s Rails 2, since the form_remote_tag is now deprecated, so the straight-forward question is: What’s the equivalent in Rails 3 for the following line (I know already I must use the form_tag keyword) ? ?:
<% form_remote_tag :url => story_votes_path(@story) do %>
But I don’t know how to get it to work so that I can still use the URL_HELPER (story_votes_path) in this case.
An additional note, the book states that in order to create the nested resource I should use the following (in routes.rb):
map.resources :stories, :has_many => :votes
However I’m inclined to say that the correct and equivalent Rails 3 way is the following:
resources :stories do
resources :votes
end
Since it correctly gives me all the routes detailed in the book by using the rake routes command:
stories_index GET /stories/index(.:format) {:controller=>“stories”, :action=>“index”}
votes_create GET /votes/create(.:format) {:controller=>“votes”, :action=>“create”}
story_votes GET /stories/:story_id/votes(.:format) {:action=>“index”, :controller=>“votes”}
POST /stories/:story_id/votes(.:format) {:action=>“create”, :controller=>“votes”}
new_story_vote GET /stories/:story_id/votes/new(.:format) {:action=>“new”, :controller=>“votes”}
edit_story_vote GET /stories/:story_id/votes/:id/edit(.:format) {:action=>“edit”, :controller=>“votes”}
story_vote GET /stories/:story_id/votes/:id(.:format) {:action=>“show”, :controller=>“votes”}
PUT /stories/:story_id/votes/:id(.:format) {:action=>“update”, :controller=>“votes”}
DELETE /stories/:story_id/votes/:id(.:format) {:action=>“destroy”, :controller=>“votes”}
stories GET /stories(.:format) {:action=>“index”, :controller=>“stories”}
POST /stories(.:format) {:action=>“create”, :controller=>“stories”}
new_story GET /stories/new(.:format) {:action=>“new”, :controller=>“stories”}
edit_story GET /stories/:id/edit(.:format) {:action=>“edit”, :controller=>“stories”}
story GET /stories/:id(.:format) {:action=>“show”, :controller=>“stories”}
PUT /stories/:id(.:format) {:action=>“update”, :controller=>“stories”}
DELETE /stories/:id(.:format) {:action=>“destroy”, :controller=>“stories”}
Well, I hope to read your comments soon, I’m really stuck here, the error I’m getting now is:
No route matches “/stories/7-some-other-story”
When I click the button that belongs to the ‘shove It’ Button.
Please Help me,
Best Regards,
Jose.