I have a model competitions that allows users to attend and withdraw from a competition. It was working well and I was changing other aspects of the site. I tested the withdraw again and the code is broken.
From a competition when I click withdraw it takes me to a page:
No route matches [GET] "/competitions/1/withdraw"
I ran $ rake routes
and received
attend_competition POST /competitions/:id/attend(.:format) competitions#attend
GET /competitions(.:format) competitions#index
POST /competitions(.:format) competitions#create
GET /competitions/new(.:format) competitions#new
edit_competition GET /competitions/:id/edit(.:format) competitions#edit
GET /competitions/:id(.:format) competitions#show
PUT /competitions/:id(.:format) competitions#update
DELETE /competitions/:id(.:format) competitions#destroy
withdraw_competition POST /competitions/:id/withdraw(.:format) competitions#withdraw
GET /competitions(.:format) competitions#index
POST /competitions(.:format) competitions#create
GET /competitions/new(.:format) competitions#new
GET /competitions/:id/edit(.:format) competitions#edit
GET /competitions/:id(.:format) competitions#show
PUT /competitions/:id(.:format) competitions#update
DELETE /competitions/:id(.:format) competitions#destroy
root /
When I withdraw it goes to the url: http://0.0.0.0:3000/competitions/1/withdraw
my config routes.rb file is
...
resources :competitions, only: [:create, :destroy, :new, :index]
...
resources :competitions do
post 'attend', on: :member
end
resources :competitions do
member do
post 'withdraw'
end
end
any help would be appreciated.
More Info
So, I have verified that my html should be sending a post request
<% if @competition.users.exclude?(@user) %>
<%= link_to 'Attend Competition', attend_competition_path(@competition.id), :method => :post %>
<% else %>
<%= link_to 'Withdraw', withdraw_competition_path(@competition.id), :method => :post %>
And they are send Get requests.
I also found that my server isn't able to find jquery-ujs which is related
application.js
//= require jquery
//= require jquery-ujs
//= require jquery-ui
//= require bootstrap
and finally my gemfile currently:
gem 'jquery-rails', '2.3.0'
gem 'jquery-ui-rails'