SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simply Rails 2 Ajax Form

    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:
    Code HTML4Strict:
    <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) ? ?:
    Code HTML4Strict:
    <% 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):
    Code Ruby:
    map.resources :stories, :has_many => :votes

    However I'm inclined to say that the correct and equivalent Rails 3 way is the following:

    Code Ruby:
    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.

  2. #2
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •