I have a rails link that's using the POST method:
link_to "Run", forecast_run_path(#forecast), method: :post
to call a defined post route:
resources :forecasts do
post :run
end
The route appears in rake routes output as expected:
forecast_run POST /forecasts/:forecast_id/run(.:format) forecasts#run
And when I inspect the page, the expected post link appears in the page:
Run Forecast
In dev it works fine, and was good in production until sometime just a few days ago - I can't find any change that seems like it should have broken it. But when I click the link, I get the error ActionController::RoutingError (No route matches [GET] "/forecasts/20/run")
I agree that no GET route matches, but it should be using POST.
This is Ruby 2.1.5, Rails 4.2.0
To my own embarrassment and for the benefit of anyone else who has the same issue:
As I switched among different clients, I didn't notice that on one of them NoScript in Firefox was blocking javascript on that site. Doh!
When you post a run, the form will direct you to the show action where it displays the newly posted run, in your case you don't have a show action for run, so implement a show action and should work fine.
Related
I cannot find out why when that following route:
get "/instagram", to: "posts#instagram", as: "instagram"
is requested by this code:
<%= link_to "Instagram", instagram_path %>
and perfectly render:
posts/instagram.html.erb
via the PostsController and following action:
def instagram
end
it does render posts/instagram.html.erb but it also try to get to this weird URL GET "/..." that I did not set up in my routes.rb or any where in the rails app.
Everything works fine on the client side and if not looking at the logs I may never have noticed this, but it bother me that this error is triggered: ActionController::RoutingError (No route matches [GET] "/...") as it does not make any sense to me.
It is possible that any ajax function is called when you click on the link, first you should check jquery is not causing the issue.
Second you should check by disabling turbolink, for particular link you can data-no-turbolink to disable turbolink.
Also try in different browser.
I am working a basic rails miniblog tutorial that is based on an older rails (dunno if that is the problem). I am trying to implement user logout (terminate a user session).
I have this in my form:
<%= link_to 'Logout', session_path(current_user), method: :delete %>
and my rake routes table looks good:
session DELETE /sessions/:id(.:format) sessions#destroy
but when I test it on local server, by clicking on 'Logout', I was given this error:
No route matches [GET] "/sessions/1"
It really should not have been a [GET] request. I checked that I included all the necessary javascript lines and bundle. What went wrong?
p.s. here is my repo: https://github.com/lukexuanliu/CornellBlog
p.p.s. my problem is very similar to this one: Routing Error No route matches [GET] "/microposts/304 - Deleting a Micropost - Michael Hartl's railstutorial.org Chapter 11
but their solution does not work for me. also, my bootstrap css is kind of messed up... dunno if that contributed to the problem
I think I found the problem. When I said "by clicking on Logout," I actually pull out the html code (using inspect element) to click on the actual code "session/1" which will mistakenly issue a [GET] request. as I clean up my stylesheets (turns out to be incompatibility of bootstrap2 code running on bootstrap3 api) and revealed the Logout button to click on, it works fine. curious.
I got an application that I turned into an engine which has tons of routes. I added the engine to a host app via Gemfile and when I run rake routes everything is displayed properly. However, in the views, the routes aren't found resulting in this error:
I access / and get following error:
No route matches {:controller=>"reports" :action=>"new"}
in file /Users/username/Sites/engine_app/app/views/home/index.html.erb:
<%= link_to 'New Report', new_report_path %>
rake routes:
...
reports#new new_report GET /:locale/reports/new(.:format)
...
Also, I can access /en/reports/new which loads the correct controller and view but get another routing error.
To me, it seems I can access any route directly but the app cannot resolve any xxx_path inside the views at all. Any suggestions?
Considering the lack of details in question, I can think only that you are trying to access it from a wrong url. /:locale/reports/new(.:format)
you probably open the url without locale:
localhos:3000/reports/new
but it should be:
localhos:3000/en/reports/new
I am creating a simple suggestion box app (to learn Rails) and am getting the following Rails routing error when I go to "/suggestion-boxes" running on my local machine (localhost:3000)
"Routing Error
No route matches [GET] "/suggestion-boxes"
In my routes.rb file I have:
SuggestionBoxApp::Application.routes.draw do
resources :suggestion_boxes
end
This is what I get when I run rake routes:
suggestion-box-app$ rake routes
suggestion_boxes GET /suggestion_boxes(.:format) suggestion_boxes#index
POST /suggestion_boxes(.:format) suggestion_boxes#create
new_suggestion_box GET /suggestion_boxes/new(.:format) suggestion_boxes#new
edit_suggestion_box GET /suggestion_boxes/:id/edit(.:format) suggestion_boxes#edit
suggestion_box GET /suggestion_boxes/:id(.:format) suggestion_boxes#show
PUT /suggestion_boxes/:id(.:format) suggestion_boxes#update
DELETE /suggestion_boxes/:id(.:format) suggestion_boxes#destroy
However, if I modify my routes file to
SuggestionBoxApp::Application.routes.draw do
get "suggestion-boxes" => "suggestion_boxes#index"
end
Then the page "/suggestion-boxes" displays as per the index action in my SuggestionBoxesController.
I tried restarting my server but this had no impact. While I of course can go with using GET, this error makes no sense, and I would like understand what is causing it.
Any insights would be very much appreciated.
The error is that you are not renaming the REST route, instead the controller one.
Try declaring
resources :suggestion_boxes, :as => "suggestion-boxes"
in your config/routes.rb file.
Somewhere in your code you are calling to suggestion-boxes controller which does not exist. Your controller is suggestion_boxes, spelling. So where every you have "suggestion-boxes" you should replace with "suggestion_boxes". The code that you added create an alias that matches 'suggestion-boxes' to the index action of the suggestion_boxes controller so this resolves it if it is your desired affect. But simply fixing your spelling would resolve your problem. I usually use the second approach if I want the change the URL that user see. Have a look at the routing doc for a better understanding
Running Rails 3.2.11, I have a regular controller "LbuController" which is basically an enhanced scaffold, enhanced by 4 additional GET methods used for AJAX requests.
resources :lbus do
get 'add_offering'
get 'remove_offering'
get 'add_offering_element'
get 'remove_offering_element'
end
running rake routes gives me the following routes
lbu_add_offering GET /lbus/:lbu_id/add_offering(.:format) lbus#add_offering
lbu_remove_offering GET /lbus/:lbu_id/remove_offering(.:format) lbus#remove_offering
lbu_add_offering_element GET /lbus/:lbu_id/add_offering_element(.:format) lbus#add_offering_element
lbu_remove_offering_element GET /lbus/:lbu_id/remove_offering_element(.:format) lbus#remove_offering_element
lbus GET /lbus(.:format) lbus#index
POST /lbus(.:format) lbus#create
new_lbu GET /lbus/new(.:format) lbus#new
edit_lbu GET /lbus/:id/edit(.:format) lbus#edit
lbu GET /lbus/:id(.:format) lbus#show
PUT /lbus/:id(.:format) lbus#update
DELETE /lbus/:id(.:format) lbus#destroy
which seem exactly to be what I intended.
But following a link to http://localhost:3000/lbus/new created with link_to "new", new_lbu_path gives me the following error:
No route matches {:action=>"add_offering", :lbu_id=>nil, :offering_id=>1, :controller=>"lbus"}
which makes absolutely no sense for me.
Anybody got any ideas what's happening here and what's going wrong?
Thanks in advance!
On the 'new' view you must have used a lbu_add_offering path.
That path seems to be incorrect. The error refers to that :action=> "add_offering".