ActionController::RoutingError (No route matches [PUT] ) for ajax call
Your routes.rb
should generate a routing of
PUT /tasks/complete
mapped to TasksController#complete
but your form is doing a
PUT /tasks
instead (from your log), so there's something wrong with the request (i.e. your form)
Can you try the following:
resources :tasks do
collection do
post :complete
end
end
<%= form_tag complete_tasks_path, format: :js, method: :post, remote: true do %>
<ul>
<% @in_completed_tasks.each do |task| %>
<li>
<%= check_box_tag "task_ids[]", task.id %>
<!--<input type="checkbox" name="task_ids[]" id="task_ids_" value="5">-->
<%= task.name %>
</li>
<% end %>
</ul>
<%= submit_tag "Submit your Answers" if @in_completed_tasks.present? %>
<% end %>
ActionController::RoutingError (No route matches [POST]
You need to pass review object to simple_form_for
:
<%= simple_form_for @review, url: user_movie_create_review_path(@movie.user, @movie), remote: true do |f| %>
..
<% end %>
`ActionController::RoutingError (No route matches [GET]` Routing Issue In Heroku, but Works on Localhost
I contacted heroku support and they had a similar answer to @AjitSingh in recommending I use AJAX:
I see what you mean. Rather than relying on tags, I would suggest
making AJAX calls to do a proper POST request, using buttons or forms.
However, AJAX is a bit above my skill level right now. I also found this little gem (no pun intended) on the ROR API about using link_to
:
method: symbol of HTTP verb - This modifier will dynamically create an
HTML form and immediately submit the form for processing using the
HTTP verb specified. Useful for having links perform a POST operation
in dangerous actions like deleting a record (which search bots can
follow while spidering your site). Supported verbs are :post, :delete,
:patch, and :put. Note that if the user has JavaScript disabled, the
request will fall back to using GET. If href: '#' is used and the user
has JavaScript disabled clicking the link will have no effect. If you
are relying on the POST behavior, you should check for it in your
controller's action by using the request object's methods for post?,
delete?, patch?, or put?.
Finally, I ended up consulting the advice of this SO post and using button_to
instead of link_to
and it fixed the issue. Whew.
No route matches [GET] after post validation error Rails 4
SOLUTION:
I needed to use an absolute path for the ajax url. Because I was using a relative path 'update_players'
in my ajax url, rails was prepending games/
on the new action but not on the create action. The routes stayed the same.
Updated assets/javascripts/games.coffee:
update_players = ->
$.ajax '/games/update_players',
type: 'GET'
dataType: 'script'
data: {
group_id: $("#groups-select option:selected").val()
}
error: (jqXHR, textStatus, errorThrown) ->
console.log("AJAX Error: #{textStatus}")
success: (data, textStatus, jqXHR) ->
console.log("Dynamic player select OK!")
$(document).on 'ready page:load', update_players
$(document).on 'change', '#groups-select', update_players
Thank you Зелёный for sending me down the right path
ActionController::RoutingError: No route matches {:controller=vendors, :action=vendors}?
Because you told it to?
The test is already contextualized, presumably with describe VendorsController
, so saying get :vendors
tells it to get the Vendors#vendors action. It isn't saying "get the /vendors URL", it's going straight to the controller.
In general, you run get :action
not get :controller
nor get :matched_route_name
Getting ActionController::RoutingError (No route matches [OPTIONS] /users when trying to POST data to RAils server with AngularJS
Rails cannot process [OPTIONS]
requests
You have to install rack-cors to process CORS.
Here's where your problem comes from:
resources :users do
collection { post :create_user , via: :options }
# via: :options ?
end
Related Topics
Rails Model Name Conflict with Included Gem
Understanding the Fibonacci Sequence
Stop Rails Console from Printing Out the Object at the End of a Loop
Is Require File.Expand_Path(..., _File_) the Best Practice
Protecting the Content of Public/ in a Rails App
Why Is Rspec So Slow Under Rails
What Does the Ruby Method 'To_Sym' Do
How to Get All Class Names in a Namespace in Ruby
How to Emit Comments in a Yaml Document Using Psych
How to Use Ruby for Shell Scripting
Cannot Access Local Sinatra Server from Another Computer on Same Network
What Should Be Removed from Public Source Control in Ruby on Rails
Ruby Mixins: Extend and Include