I am using this tutorial , and have developed a simple application called ponies
this is what I have in view page ,
<% @ponies.each do |pony| %>
<tr>
<td><%= link_to 'Destroy', pony, method: :delete, data: { confirm: 'Are you sure?' }, :remote => true, :class => 'delete_pony' %> </td>
</tr>
<% end %>
and in the controller :
def destroy
@pony = Pony.find(params[:id])
@pony.destroy
respond_to do |format|
format.html { redirect_to ponies_url }
format.json { head :no_content }
format.js { render :layout => false }
end
end
clearly when i click on th link Destroy , script 'destroy.js.erb' file is executed
alert("in destroy.js.erb");
$('.delete_pony').bind('ajax:success', function() {
alert("in destroy.js.erb inside ajax success");
$(this).closest('tr').fadeOut();
})
and succesfully deletes the pony object
but i create an extra link
<td><%= link_to 'hussi', pony , method: :post, data: { confirm: 'Are you sure?' }, :remote => true, :class => 'preview_pony' %></td>
created preview method in controller
def preview
@pony = Pony.find(params[:id])
@hussi = @pony.name
puts @hussi
respond_to do |format|
format.html { redirect_to ponies_url }
format.json { head :no_content }
format.js { render :layout => false }
end
end
and also created file 'preview.js.erb'
alert("in preview.js.erb");
$('.preview_pony').bind('ajax:success', function()
{
alert("you did it , hussain");
})
but on clicking th elink preview , script written inside 'preview.js.erb' is never called , any explanation why ??
and also in first link we use HTTP method :delete
now if i want simply to display some simeple method or to fade in/out some html element , what http method should i use
in the line :
<%= link_to 'hussi', pony , method: :post, data: { confirm: 'Are you sure?' }, :remote => true, :class => 'preview_pony' %>
what object should i pass in place of 'pony' what method should i use in place of ':delete' method