I have a nested resource attachments and I want to create a link_to to destroy/delete the attachment. Here's what I have, but it is posting as a GET versus a PUT:
<%= link_to "Delete Attachment", project_thread_attachment_path(#attachment.thread.project.id, #attachment.thread.id, #attachment.id), :confirm => "Are you sure you want to delete this attachment?", :method => :delete, :action => "destroy" %>
Ideas? Thanks!
Try
link_to "Delete Attachment", [#attachment.thread.project,#attachment.thread,#attachment], :confirm => "Are you sure?", :method => :delete
Does it work?
You should be able to use the following by itself (remove the :action => 'destroy' part). Also, the request should be a DELETE request, not a PUT request:
<%= link_to "Delete Attachment", project_thread_attachment_path(#attachment.thread.project.id, #attachment.thread.id, #attachment.id), :confirm => "Are you sure you want to delete this attachment?", :method => :delete %>
Related
<%= link_to "[Delete]", customer_path(customer.id, :customer_delete => true), :method => :delete, :data => {:confirm => "Are You Sure?"} %>
My above code working fine,
But how to give my link_to a color say ike red in my view ? Tried many stack overflow threads but couldn't find a solution as my link_to contains a combine functionality like data confirmation action with passing parameters
To give color property to Link
1. new link with css class
<%= link_to "[Delete]", customer_path(customer.id, :customer_delete => true), :method => :delete, :data => {:confirm => "Are You Sure?"}, :class => 'link' %>
application.css
.link {
color: red;
}
2. new link with inline css style
<%= link_to "[Delete]", customer_path(customer.id, :customer_delete => true), :method => :delete, :data => {:confirm => "Are You Sure?"}, :style => 'color: red;' %>
The following :confirm pops up a window asking 'Delete the record?':
<%= link_to t('Delete'), misc_definition_path(#misc_definition), :method => :delete, :confirm => 'Delete the record?'
If adding I18n.t() to the message, however the confirm window does not pop up:
<%= link_to t('Delete'), misc_definition_path(#misc_definition), :method => :delete, :confirm => I18n.t('Delete the record?')
I tried "#{I18n.t()}" and not working. Is there a way the message can be I18n.t?
The syntax is correct.
Try this -
Add some key in your config/locales/*.yml
confirm_delete: 'Delete Record'
Use this key as-
<%= link_to t('Delete'), misc_definition_path(#misc_definition), :method => :delete, :confirm => I18n.t('confirm_delete') %>
Given the following:
<%= link_to "Add", group_request_path(gr), :confirm => "Are you sure?", :method=> :put, :remote => true %>
<%= link_to "Ignore", group_request_path(gr), :confirm => "Are you sure?", :method=> :put, :remote => true %>
How can I pass a decision param with either add or ignore in the link_to's above? Is there an option to add a URL param somehow with a link_to? I don't want to have to use forms.
the *_path helpers accept a hash of options to append to the path as a query string.
In your example, assuming group_request_path(gr) outputs something like /group_requests/123, you could add a query string with add/ignore actions like this:
group_request_path(gr, :action => 'add') # /groups_requests/123?action=add
or
group_request_path(gr, :add => 1) # /groups_requests/123?add=1
However this probably isn't the correct way of going about this. It looks like you should probably have distinct actions in your controller, and routes specific to adding or ignoring. You'll have to add something like the following to config/routes.rb:
put 'group_requests/:id/add' => 'groups_requests#add', :as => :add_group_request
put 'group_requests/:id/ignore' => 'groups_requests#ignore', :as => :ignore_group_request
Your links then become
<%= link_to "Add", add_group_request_path(gr), :confirm => "Are you sure?", :method=> :put, :remote => true %>
<%= link_to "Ignore", ignore_group_request_path(gr), :confirm => "Are you sure?", :method=> :put, :remote => true %>
I'm using the following for a delete link:
<%= link_to "Delete", photo_path(#photo.id), :confirm => "Are you sure?", :method=>:delete %>
Problem is, if I click CANCEL - it still deletes!!! wooops... Why is that?
First, you don't have to write photo_path(#photo.id), just pass #photo, that's enough.
<%= link_to "Delete", #photo, :confirm => "Are you sure?", :method => :delete %>
If the link doesn't work, that means that your page doesn't correctly load the JavaScript adaptator for your JavaScript framework. For example, if you use use jQuery, check this :
http://github.com/rails/jquery-ujs
I have a link_to like this:
<%= link_to 'X', category, :confirm => 'Are you sure?', :method => :delete %>
So, I change it like this:
<%=link_to_remote category.name,
:confirm => 'Are you sure?', :method => :delete%>
it show the confirm box, but after I click "yes", it won't delete the item I want , why?
There is no information about what url you need to go to in your link_to_remote usage. You should also specify something like
:url => delete_category_path(category)
in the options hash.