Problem z gemem: Act_as_votable

Witam,

mam mały problem z gemem act_as_votable.
Chciałem umożliwić plusowanie postów na stronie głównej unikalnym gościom. Dlatego stworzyłem model Session (z polem ip) i podpiąłem go do metody.

Pełny kod: https://github.com/dyzajash/motoko

Wcześniej gdy stosowałem tą konstrukcję:

  def upvote
    @post = Post.friendly.find(params[:id])
    @voter = Session.find_or_create_by(ip: request.remote_ip)
    @post.liked_by @voter

    redirect_to :back
   end

Wszystko działało poprawnie. Niestety każdy plus powodował odświeżanie całej witryny, dlatego zdecydowałem się na podpięcie jquery do tego. I tu zaczęły się schody. Po zmianie mojej metody na:

  def upvote
    @post = Post.friendly.find(params[:id])
    @voter = Session.find_or_create_by(ip: request.remote_ip)
    @post.liked_by @voter

    respond_to do |format|
      format.html { redirect_to :back }
      format.json { render json: { count: @post.get_likes.size } }
    end
  end 

oraz zmiany templatki z:

    <div class="thanks">
      <%= link_to "#{post.get_likes.size} | PODZIĘKOWAŃ", like_post_path(post), method: :put, class: 'vote' %>
    </div>

na

    <div class="thanks">
      <%= link_to "#{post.get_likes.size} | PODZIĘKOWAŃ", like_post_path(post), method: :put, class: 'vote', remote: true %>
    </div>

zaczęło wyrzucać mi błędy gdy ktoś drugi raz próbował ‘podziękować’ za ten sam post. Treść błędu:

Started PUT “/” for 127.0.0.1 at 2015-05-10 12:10:01 +0200

ActionController::RoutingError (No route matches [PUT] “/”):
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call' web-console (2.1.2) lib/web_console/middleware.rb:37:incall’
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.2.1) lib/rails/rack/logger.rb:38:incall_app’
railties (4.2.1) lib/rails/rack/logger.rb:20:in block in call' activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:inblock in tagged’
activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in tagged' activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:intagged’
railties (4.2.1) lib/rails/rack/logger.rb:20:in call' quiet_assets (1.1.0) lib/quiet_assets.rb:27:incall_with_quiet_assets’
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.6.0) lib/rack/methodoverride.rb:22:incall’
rack (1.6.0) lib/rack/runtime.rb:18:in call' rack (1.6.0) lib/rack/lock.rb:17:incall’
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in call' rack (1.6.0) lib/rack/sendfile.rb:113:incall’
railties (4.2.1) lib/rails/engine.rb:518:in call' railties (4.2.1) lib/rails/application.rb:164:incall’
rack (1.6.0) lib/rack/lock.rb:17:in call' rack (1.6.0) lib/rack/content_length.rb:15:incall’
rack (1.6.0) lib/rack/handler/webrick.rb:89:in service' /Users/msmolik/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:138:inservice’
/Users/msmolik/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:94:in run' /Users/msmolik/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/server.rb:294:inblock in start_thread’

Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (0.6ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb (13.4ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb (0.4ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.3ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb within layouts/javascript (36.9ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb within layouts/javascript (0.4ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.5ms)
Rendered /Users/msmolik/.rvm/gems/ruby-2.2.2/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb (81.8ms)

Moje pytanie: jak zabezpieczyć się przed tego typu błędem? Co muszę zmienić w swojej logice aplikacji żeby przestało mi to wyrzucać RoutingErrory?