Note that there are some explanatory texts on larger screens.

plurals
  1. PORails: Routing error when using ajax with a button
    text
    copied!<p>I am new to rails and have followed the answer on this <a href="https://stackoverflow.com/questions/6899037/rails-ajax-fav-button-for-user-posts">question</a>. </p> <p>This is how things are in my project:</p> <p>Controller:</p> <pre><code>def create def create current_user.likes.create(:post_id =&gt; params[:post_id]) render :layout =&gt; false end end </code></pre> <p>.js file:</p> <pre><code>$ -&gt; $(".like").click -&gt; post_id = $(this).attr('id') $.ajax type: 'POST' url: 'likes/' + post_id success: -&gt; alert "succsess!" </code></pre> <p>Routes.rb</p> <pre><code>Sample::Application.routes.draw do resources :likes resources :users resources :sessions, only: [:new, :create, :destroy] resources :posts, only: [:create, :destroy] root to: 'pages#home' match '/about', to: 'pages#about' match '/contact', to: 'pages#contact' match '/help', to: 'pages#help' match '/signup', to: 'users#new' match '/signin', to: 'sessions#new' match '/signout', to: 'sessions#destroy' post '/likes/4', to: 'likes#create', :as =&gt; :like end </code></pre> <p>(I use '/likes/4' for testing proposes (it will be 'post_id' in the future)).</p> <p>When I click on the Like button in the view, the like get stored in the db, but I get this error(when I look at the console with inspector in Chrome)... </p> <pre><code>POST http://0.0.0.0:3000/likes/4 500 (Internal Server Error) </code></pre> <p>...and I never get the succsess alert from the ajax.</p> <p>When I run <code>wget --post-data='' http://localhost:3000/likes/4</code>, I get:</p> <pre><code>--2012-07-22 19:35:01-- http://localhost:3000/likes/4 Resolving localhost... ::1, 127.0.0.1, fe80::1 Connecting to localhost|::1|:3000... failed: Connection refused. Connecting to localhost|127.0.0.1|:3000... connected. HTTP request sent, awaiting response... 500 Internal Server Error 2012-07-22 19:35:02 ERROR 500: Internal Server Error. </code></pre> <p>Anyone know what makes this error?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload