Ruby app: link_to 'delete' looking for GET - ruby-on-rails

I realize this question has been asked many times, but I've tried all the solutions I can find, and have gotten nowhere.
In my view, I have
= link_to "Delete", evint_path(e), :method => :delete, data: {:confirm => 'Are you sure?'}
where e is an instance of evint. I keep getting error messages declaring that I'm missing a GET method for evint:
No route matches [GET] "/evints/5"
This isn't even the case! When I rake routes, I have a GET route for evints.
I have jquery-rails in my Gemfile; I have "require jquery_ujs" in my application.js file. I have five other apps on the same system that work, so I don't think it's a system problem.
The html being generated by my code looks OK:
<a rel="nofollow" href="/evints/5" data-method="delete" data-confirm="Are you sure?">Delete</a>
I've tried removing "//= require tree ." from my application.js file, but that didn't make any difference.
I'm also having trouble signing out of my app, as devise's destroy_session also isn't working!
Does anybody have any ideas? This is driving me crazy!
EDIT: Here are my routes:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
interests GET /interests(.:format) interests#index
POST /interests(.:format) interests#create
new_interest GET /interests/new(.:format) interests#new
edit_interest GET /interests/:id/edit(.:format) interests#edit
interest GET /interests/:id(.:format) interests#show
PATCH /interests/:id(.:format) interests#update
PUT /interests/:id(.:format) interests#update
DELETE /interests/:id(.:format) interests#destroy
events GET /events(.:format) events#index
POST /events(.:format) events#create
new_event GET /events/new(.:format) events#new
edit_event GET /events/:id/edit(.:format) events#edit
event GET /events/:id(.:format) events#show
PATCH /events/:id(.:format) events#update
PUT /events/:id(.:format) events#update
DELETE /events/:id(.:format) events#destroy
images GET /images(.:format) images#index
POST /images(.:format) images#create
new_image GET /images/new(.:format) images#new
image GET /images/:id(.:format) images#show
DELETE /images/:id(.:format) images#destroy
evints GET /evints(.:format) evints#index
POST /evints(.:format) evints#create
new_evint GET /evints/new(.:format) evints#new
evint DELETE /evints/:id(.:format) evints#destroy
projects GET /projects(.:format) projects#index
POST /projects(.:format) projects#create
new_project GET /projects/new(.:format) projects#new
edit_project GET /projects/:id/edit(.:format) projects#edit
project PATCH /projects/:id(.:format) projects#update
PUT /projects/:id(.:format) projects#update
projectimages GET /projectimages(.:format) projectimages#index
POST /projectimages(.:format) projectimages#create
new_projectimage GET /projectimages/new(.:format) projectimages#new
projectimage GET /projectimages/:id(.:format) projectimages#show
DELETE /projectimages/:id(.:format) projectimages#destroy
welcome_index GET /welcome/index(.:format) welcome#index
root GET / welcome#index
welcome_readpdf GET /welcome/readpdf(.:format) welcome#readpdf

Related

Rails Redirect to an Anchor Tag from the Controller

I am using Comments table as polymorphic associations. When i save the comment and it redirects to the respective associated model. I want it to pass an anchor tag to auto scroll down to display the comments. Am trying the following but the anchor tag is not passing to the url
#comment = #commentable.comments.new comment_params
#comment.user = current_user
#comment.save
redirect_to #commentable, :anchor => '#comments'
Rake Routes
Prefix Verb URI Pattern Controller#Action
rate POST /rate(.:format) rater#create
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root GET / welcome#index
artists GET /artists(.:format) artists#index
POST /artists(.:format) artists#create
new_artist GET /artists/new(.:format) artists#new
edit_artist GET /artists/:id/edit(.:format) artists#edit
artist GET /artists/:id(.:format) artists#show
PATCH /artists/:id(.:format) artists#update
PUT /artists/:id(.:format) artists#update
DELETE /artists/:id(.:format) artists#destroy
album_comments GET /albums/:album_id/comments(.:format) albums/comments#index
POST /albums/:album_id/comments(.:format) albums/comments#create
new_album_comment GET /albums/:album_id/comments/new(.:format) albums/comments#new
edit_album_comment GET /albums/:album_id/comments/:id/edit(.:format) albums/comments#edit
album_comment GET /albums/:album_id/comments/:id(.:format) albums/comments#show
PATCH /albums/:album_id/comments/:id(.:format) albums/comments#update
PUT /albums/:album_id/comments/:id(.:format) albums/comments#update
DELETE /albums/:album_id/comments/:id(.:format) albums/comments#destroy
albums GET /albums(.:format) albums#index
POST /albums(.:format) albums#create
new_album GET /albums/new(.:format) albums#new
edit_album GET /albums/:id/edit(.:format) albums#edit
album GET /albums/:id(.:format) albums#show
PATCH /albums/:id(.:format) albums#update
PUT /albums/:id(.:format) albums#update
DELETE /albums/:id(.:format) albums#destroy
song_comments GET /songs/:song_id/comments(.:format) songs/comments#index
POST /songs/:song_id/comments(.:format) songs/comments#create
new_song_comment GET /songs/:song_id/comments/new(.:format) songs/comments#new
edit_song_comment GET /songs/:song_id/comments/:id/edit(.:format) songs/comments#edit
song_comment GET /songs/:song_id/comments/:id(.:format) songs/comments#show
PATCH /songs/:song_id/comments/:id(.:format) songs/comments#update
PUT /songs/:song_id/comments/:id(.:format) songs/comments#update
DELETE /songs/:song_id/comments/:id(.:format) songs/comments#destroy
songs GET /songs(.:format) songs#index
POST /songs(.:format) songs#create
new_song GET /songs/new(.:format) songs#new
edit_song GET /songs/:id/edit(.:format) songs#edit
song GET /songs/:id(.:format) songs#show
PATCH /songs/:id(.:format) songs#update
PUT /songs/:id(.:format) songs#update
DELETE /songs/:id(.:format) songs#destroy
GET /get_albums_of_artist/:artist_id(.:format) songs#get_albums_of_artist
Remove the # symbol in your anchor string and call anchor: within the url helper method: redirect_to comments_path(anchor: 'anchor_tag')
Alright, from rails DOC url_for() method should return URL of given object.
redirect_to "#{url_for(#commentable)}#comments"
if its nested then url_for([#product, #comment])

link_to not passing params properly

the view
<td><%= link_to "+1", :controller => :profiles, :action => :addpoints, :profile_id => profile.id, :task_id => #task.id%></td>
When trying to access profile.id via :profile_id rails returns an error, the id was not passed at all. How do I fix this? What's the best way to pass two params through two models? rake routes
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
static_pages_home GET /static_pages/home(.:format) static_pages#home
static_pages_dashboard GET /static_pages/dashboard(.:format) static_pages#dashboard
static_pages_pending GET /static_pages/pending(.:format) static_pages#pending
static_pages_taskcompleted GET /static_pages/taskcompleted(.:format) static_pages#taskcompleted
tasks_index GET /tasks/index(.:format) tasks#index
tasks_complete GET /tasks/complete(.:format) tasks#complete
tasks_delete GET /tasks/delete(.:format) tasks#delete
profiles_addpoints GET /profiles/addpoints(.:format) profiles#addpoints
profiles_index GET /profiles/index(.:format) profiles#index
root GET / static_pages#home
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
tasks GET /tasks(.:format) tasks#index
POST /tasks(.:format) tasks#create
new_task GET /tasks/new(.:format) tasks#new
edit_task GET /tasks/:id/edit(.:format) tasks#edit
task GET /tasks/:id(.:format) tasks#show
PATCH /tasks/:id(.:format) tasks#update
PUT /tasks/:id(.:format) tasks#update
DELETE /tasks/:id(.:format) tasks#destroy
profiles GET /profiles(.:format) profiles#index
POST /profiles(.:format) profiles#create
new_profile GET /profiles/new(.:format) profiles#new
edit_profile GET /profiles/:id/edit(.:format) profiles#edit
profile GET /profiles/:id(.:format) profiles#show
PATCH /profiles/:id(.:format) profiles#update
PUT /profiles/:id(.:format) profiles#update
DELETE /profiles/:id(.:format) profiles#destroy
Replace profile.id with #profile.id. Verify that profile is actually an instance. A nil value may be being passed in (as opposed to things being wired incorrectly).
Can we see the method content ?
If the error is about the id, the route is correct. What's in params[:profile_id] ? We need more info here..
I think this is what you wanted to do in Rails 4 way.
<%= link_to "+1", profiles_addpoints_path(:profile_id => profile.id, :task_id => #task.id) %>
That code above will call addpoints method in profiles controller with parameter {:profile_id => profile.id, :task_id => #task.id}. You can access parameter like this.
params[:profile_id] and params[:task_id].
Another thing that's worrysome about your code is that in the routes.rb, profiles_addpoints route is called via GET HTTP verb. This is potentially dangerous because Google search bots will visit these paths and result in a spike in upvotes. Respect HTTP convention and use PUT.

difficulty with member routes

UPDATE: This was all a horrible mistake - I was updating the wrong routes file!
this does work: get 'users/:id/groups/' => 'users#groups'
I'd like to be able to see groups that belong to a specific user but I'm having trouble setting up a route that would resolve to:
/users/:id/groups
for some reason. I'm guessing devise is getting in the way, perhaps.
i've tried the following:
resources :users
match '/users/:id/groups', to: 'users#groups', via: :get
and
resources :users do
member do
get 'groups'
end
end
such a route never shows up when i call rake routes:
$ rake routes
Prefix Verb URI Pattern Controller#Action
groups GET /groups(.:format) groups#index
POST /groups(.:format) groups#create
new_group GET /groups/new(.:format) groups#new
edit_group GET /groups/:id/edit(.:format) groups#edit
group GET /groups/:id(.:format) groups#show
PATCH /groups/:id(.:format) groups#update
PUT /groups/:id(.:format) groups#update
DELETE /groups/:id(.:format) groups#destroy
calendar GET /calendar(/:year(/:month))(.:format) calendar#index {:year=>/\d{4}/, :month=>/\d{1,2}/}
root GET / calendar#index
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PATCH /users(.:format) registrations#update
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
accept_user_invitation GET /users/invitation/accept(.:format) devise/invitations#edit
remove_user_invitation GET /users/invitation/remove(.:format) devise/invitations#destroy
user_invitation POST /users/invitation(.:format) devise/invitations#create
new_user_invitation GET /users/invitation/new(.:format) devise/invitations#new
PATCH /users/invitation(.:format) devise/invitations#update
PUT /users/invitation(.:format) devise/invitations#update
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
events GET /events(.:format) events#index
POST /events(.:format) events#create
new_event GET /events/new(.:format) events#new
edit_event GET /events/:id/edit(.:format) events#edit
event GET /events/:id(.:format) events#show
PATCH /events/:id(.:format) events#update
PUT /events/:id(.:format) events#update
DELETE /events/:id(.:format) events#destroy
Why are you specifying member when you're trying to nest the resource? Did you try simply
resources :users do
resources :groups, only: :index
end

Rails routing to the wrong controller action

Here is the output of 'rake routes'
$ rake routes
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
admin_root /admin(.:format) admin/dashboard#index
admin_dashboard /admin/dashboard(.:format) admin/dashboard#index
admin_user PUT /admin/users/:id(.:format) admin/users#update
batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action
admin_users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
new_admin_user GET /admin/users/new(.:format) admin/users#new
edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit
GET /admin/users/:id(.:format) admin/users#show
PUT /admin/users/:id(.:format) admin/users#update
DELETE /admin/users/:id(.:format) admin/users#destroy
root / home#index
And here is an excerpt from the logs
Started POST "/admin/users/batch_action" for 127.0.0.1 at 2013-01-18 23:07:07 +0530
Processing by Admin::UsersController#create as HTML
Why is /admin/users/batch_action getting routed to Admin::UsersController#create, when the routes shows
batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action
I am using ActiveAdmin and these are the routes that it generates.
It seems like you are using resources for routing admin/users controller, so POST http verb is defaulted to create action in the controller.
If you would like to add another restful POST controller action, do something like this,
scope "admin" do
resources :users do
member do
post 'batch_action'
end
end
end
I don't know how your routes.rb looks like, so it might look different in your routes.rb file. But it should look similar.

Weird issue with my rails path and its routing

I'm getting a strange error with my routing. I've installed the blogit gem but I don't think this is causing this problem.
undefined local variable or method `locations_path'
Here is my routes file:
AppName::Application.routes.draw do
devise_for :users
root :to => 'locations#index'
mount Blogit::Engine => "/blog", :as => "blog"
resources :locations do
collection do
get 'location'
end
end
and here's my rake routes:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root / locations#index
blog /blog Blogit::Engine
location_locations GET /locations/location(.:format) locations#location
locations GET /locations(.:format) locations#index
POST /locations(.:format) locations#create
new_location GET /locations/new(.:format) locations#new
edit_location GET /locations/:id/edit(.:format) locations#edit
location GET /locations/:id(.:format) locations#show
PUT /locations/:id(.:format) locations#update
DELETE /locations/:id(.:format) locations#destroy
Routes for Blogit::Engine:
/posts/page/:page(.:format) blogit/posts#index
tagged_blog_posts /posts/tagged/:tag(.:format) blogit/posts#tagged
post_comments POST /posts/:post_id/comments(.:format) blogit/comments#create
post_comment DELETE /posts/:post_id/comments/:id(.:format) blogit/comments#destroy
posts GET /posts(.:format) blogit/posts#index
POST /posts(.:format) blogit/posts#create
new_post GET /posts/new(.:format) blogit/posts#new
edit_post GET /posts/:id/edit(.:format) blogit/posts#edit
post GET /posts/:id(.:format) blogit/posts#show
PUT /posts/:id(.:format) blogit/posts#update
DELETE /posts/:id(.:format) blogit/posts#destroy
root / blogit/posts#index
Any suggestions as to why this may be happening would be great.
Thanks,
James
This was an issue with my blogit configuration.
People can find the full thread here:
https://github.com/KatanaCode/blogit/issues/8
Thanks for all your help!
James

Resources