Friday 15 August 2014

ruby on rails - No route matches for destroy action -



ruby on rails - No route matches for destroy action -

the destroy action working me in 1 part of app, can't work in different view using separate controller.

i getting error: no route matches {:action=>"destroy", :controller=>"letsgo"}

view:

<% letsgo in @letsgos %> <li> <b>let's go...<span class="content"><%= letsgo.content %></span></b> <%= link_to 'delete', { :controller => 'letsgo', :action => 'destroy'}, { :confirm => 'are sure?', :method => :delete, :remote => true} %> <% end %>

routes:

resources :letsgos, only: [:create, :destroy]

letsgos controller:

def destroy @letsgo.destroy redirect_to root_url end

this code works if under letsgos view: <%= link_to "delete", letsgo, method: :delete, data: { confirm: "you sure?" }%>

destroy action works if working under letsgos view, working under different folder no longer works. doing listing content letsgos table, , providing destroy action each content.

routes:

letsgos_eatdrink /letsgos/eatdrink(.:format) letsgos#eatdrink letsgos_listenwatch /letsgos/listenwatch(.:format) letsgos#listenwatch letsgos_play /letsgos/play(.:format) letsgos#play letsgos_other /letsgos/other(.:format) letsgos#other letsgos_explore /letsgos/explore(.:format) letsgos#explore repost_letsgo post /letsgos/:id/repost(.:format) letsgos#repost interested_letsgo post /letsgos/:id/interested(.:format) letsgos#interested /letsgos(.:format) letsgos#index post /letsgos(.:format) letsgos#create new_letsgo /letsgos/new(.:format) letsgos#new edit_letsgo /letsgos/:id/edit(.:format) letsgos#edit /letsgos/:id(.:format) letsgos#show patch /letsgos/:id(.:format) letsgos#update set /letsgos/:id(.:format) letsgos#update delete /letsgos/:id(.:format) letsgos#destroy

you not passing id of letsgo route:

<%= link_to 'delete', { :controller => 'letsgos', :action => 'destroy', :id => letsgo.id }, { :confirm => 'are sure?', :method => :delete, :remote => true} %>

as written in paths:

letsgo delete /letsgos/:id(.:format) letsgos#destroy

it's not tested, should this

ruby-on-rails

No comments:

Post a Comment