Issue with routing

17 views
Skip to first unread message

Andrew Dig

unread,
Feb 23, 2016, 1:53:09 AM2/23/16
to rubyonra...@googlegroups.com
Hi everyone. I'm newbe in ROR and recently faced with a routing problem.
Here's my route:

post ':type/delete/:id' => 'todolist#delete_item', as: 'delete',
constraints: {type: 'project|task'}

my link:

<%= link_to '', delete_path(type:'project',id: project.id),{class:
'glyphicon glyphicon-trash',data:{project_id: project.id},remote:
true}%>

I get an error No route matches [GET] "/project/delete/158" WHY GET
method???

routes:
todolist_index GET /todolist/index(.:format) todolist#index
sessions_new GET /sessions/new(.:format) sessions#new
users_new GET /users/new(.:format) users#new
log_out GET /log_out(.:format) sessions#destroy
log_in GET /log_in(.:format) sessions#new
sign_up GET /sign_up(.:format) users#new
root GET / users#new
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
sessions GET /sessions(.:format) sessions#index
POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
edit_session GET /sessions/:id/edit(.:format) sessions#edit
session GET /sessions/:id(.:format) sessions#show
PATCH /sessions/:id(.:format) sessions#update
PUT /sessions/:id(.:format) sessions#update
DELETE /sessions/:id(.:format) sessions#destroy
todo GET /todo_list(.:format) todolist#index
add_project POST /add_project(.:format) todolist#add_project
edit_project POST /edit_project(.:format) todolist#edit_project
POST /:add_task/:id(.:format) todolist#add_task
delete POST /:type/:id(.:format) todolist#delete_item
{:type=>"project|task"}

--
Posted via http://www.ruby-forum.com/.

Tamara Temple

unread,
Feb 23, 2016, 6:10:56 AM2/23/16
to rubyonra...@googlegroups.com

Andrew Dig <li...@ruby-forum.com> writes:

> Hi everyone. I'm newbe in ROR and recently faced with a routing problem.
> Here's my route:
>
> post ':type/delete/:id' => 'todolist#delete_item', as: 'delete',
> constraints: {type: 'project|task'}
>
> my link:
>
> <%= link_to '', delete_path(type:'project',id: project.id),{class:
> 'glyphicon glyphicon-trash',data:{project_id: project.id},remote:
> true}%>

link_to by default uses the GET method. You can tell it to use POST by
supplying method: :post in the parameter hash.

You might consider, since you're performing a delete action of some sort,
using the HTTP verb DELETE instead, but that's entirely up to you.
--
Tamara Temple
tam...@gmail.com
http://www.tamouse.org

Andrew Dig

unread,
Feb 23, 2016, 7:35:51 AM2/23/16
to rubyonra...@googlegroups.com
Thx very much. I tried to use method: post but couldn't figure out how
to do that properly(I mean syntax).So how it should be correctly?!

<%= link_to { delete_path(type:'project',id: project.id),remote:
true, method: post},{class:
'glyphicon glyphicon-trash',data:{project_id: project.id} do }%>

Andrew Dig

unread,
Feb 23, 2016, 3:49:56 PM2/23/16
to rubyonra...@googlegroups.com
I fixed thks for help!!!appreciated
Reply all
Reply to author
Forward
0 new messages