Ruby On Rails strange routes path - ruby-on-rails

I have this routes in my app (rails 3.2):
godmode_invites GET /godmode/invites(.:format) godmode/invites#index
POST /godmode/invites(.:format) godmode/invites#create
new_godmode_invite GET /godmode/invites/new(.:format) godmode/invites#new
edit_godmode_invite GET /godmode/invites/:id/edit(.:format) godmode/invites#edit
godmode_invite GET /godmode/invites/:id(.:format) godmode/invites#show
PUT /godmode/invites/:id(.:format) godmode/invites#update
DELETE /godmode/invites/:id(.:format) godmode/invites#destroy
And in template view:
<td><%= link_to 'Show', godmode_invites_path(invite) %></td>
<td><%= link_to 'Destroy', godmode_invites_path(invite), method: :delete, data: { confirm: 'Are you sure?' } %></td>
This produces strange routes like with point before resource ID:
/godmode/invites.3
/godmode/invites.4
I can not find my problem...

There is little error your in view. Here is the corrected code:
<td><%= link_to 'Show', godmode_invite_path(invite) %></td>
<td><%= link_to 'Destroy', godmode_invite_path(invite), method: :delete, data: { confirm: 'Are you sure?' } %></td>

Related

Rails index.html.erb delete item - not working

Trying to delete an item from index.html.erb with following code:
<td><%= link_to 'Delete', method: :delete, id: product.id, data: { confirm: 'Are you sure?' } %></td>
however all it does is try to show the index again. How can I be more specific, I.e. - if this is a product from a category, how to I reference the path to this object in the database to delete it?
Define your action for delete and implement deleting a product in there.

Rails No route matches [DELETE]

Trying to delete a reply
<% #comment.replies.each do |reply| %>
<td><%= link_to 'Destroy', comment_replies_path(reply), method: :delete, data: { confirm: 'Are you sure?' }%></td>
I do receive the following error
No route matches [DELETE] "/comments/66/replies"
rake routes
comment_reply_path
DELETE /comments/:comment_id/replies/:id(.:format) replies#destroy
The url that I am at this point is
http://localhost:3000/comments/66/replies
routes.rb
resources :comments do
resources :replies
end
Your route says comment_reply_path and you are using comment_replies_path
You need to update your code to use correct path helper
<%= link_to 'Destroy', comment_reply_path(reply), method: :delete, data: { confirm: 'Are you sure?' }%>

Ruby on Rails- Destroy record using link

I want to delete a record that is stored in a table using a link right next to the table data. The error I come up with is:
No route matches [GET] "/carlogs/destroy"
My destroy method:
def destroy
#carlog= CarLog.find(params[:id])
#carlog.destroy()
redirect_to show_path(#carlog)
end
Part of the view code containing the Delete link:
<% #carlogs.each do |car| %>
<tr>
<td><%= car.id %></td>
<td><%= car.plate_number %></td>
<td><%= car.brand %></td>
<td><%= car.slot_number %></td>
<td><%= car.is_taken %></td>
<td><%= car.created_at %></td>
<td><%= link_to "Delete", show_path(car), method: :delete, data:
{confirm: "Are you sure?"} %>
</tr>
<% end %>
Make sure that you have delete REST method as:
DELETE /carlogs/:id(.:format) carlogs#destroy
And in your application.js you must have this line:
//= require jquery_ujs
Use destroy link for destroy record then redirect table like
method
def destroy
#carlog= CarLog.find(params[:id])
#carlog.destroy()
redirect_to show_path(#carlog) #-> Table pathe
end
routes.rb
delete 'destroy' => 'carlogs#destroy'
View
<%= link_to "Delete", destroy_path, method: :delete, data:
{confirm: "Are you sure?"} %>
I think will help you
Why did you write show_path(car)?
Maybe you mean car_path(car) ?
<%= link_to "Delete", car_path(car), method: :delete, data:
{confirm: "Are you sure?"}%>
Also you should check your route [GET] "/carlogs/destroy.
I think this don't present in rake router

Append pdf extension to link

I know this has to be a duplicate question - I did search for it, but could not find any answers.
I'm trying to do a simple link to some documents from the index view of my rails application. I'm using the wkhmtltopdf plugin via the PDFkit gem. I'm able to simply append the .pdf extension to any page and get a pdf copy. That part works great, I just can seem to figure out the proper syntax to append a format. Here's what I have so far:
<tr>
shortened for brevity's sake
<td><%= link_to 'Show', certification %></td>
<td><%= link_to 'Edit', edit_certification_path(certification) %></td>
<td><%= link_to 'Destroy', certification, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to "Download PDF", certification_path(#certification, :format => "pdf") %></td>
</tr>
I was trying to follow Ryan's method from the PDFkit Railscast Episode, but it seems his method must be deprecated or I might have done something wrong.
<tr>
shortened for brevity's sake
<td><%= link_to 'Show', certification %></td>
<td><%= link_to 'Edit', edit_certification_path(certification) %></td>
<td><%= link_to 'Destroy', certification, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to "Download PDF", certification_path(#certification, :format => "pdf") %></td>
</tr>
Okay from your code it seems you have used certification and #certification. From your comment before which says nil doesn't exist, #certifcation doesn't have any value in it.
So i believe the correct fix in your case is.
<td><%= link_to "Download PDF", certification_path(certification, :format => "pdf") %></td>

How to do delete link in rails with modules

So I am unsure of the syntax for the delete record link because I have modules for the routes
namespace :api do
namespace :v1 do
resources :invites do
collection do
post "by_user_id"
end
end
end
end
This is the syntax for the delete method right now
<td><%= link_to 'Destroy', invite, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Also I am using rails 4
Please check routes via rake routes DELETE method for invites resource.
Then insert your routes below in place of "your_routes_path"
<td><%= link_to 'Destroy', your_routes_path, method: :delete, data: { confirm: 'Are you sure?' } %></td>

Resources