Note that there are some explanatory texts on larger screens.

plurals
  1. POlink_to delete post
    primarykey
    data
    text
    <p>I have this code:</p> <pre><code>&lt;table&gt; &lt;% @posts.each do |post| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= post.created_at.utc.strftime("%d.%m.%Y") %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to(post.title, {:controller=&gt;:blog,:action=&gt;:show, :id=&gt;post}) %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Edit', edit_post_path(post) %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Destroy', {:controller=&gt;:posts,:action=&gt;:destroy, :id=&gt;post}, :method=&gt;:delete %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; </code></pre> <p></p> <p>Problem is that link_to 'Destroy' isn't deleting posts, but just open them. Any suggestions to solve this?</p> <p>routes.rb file:</p> <pre><code>LivuPamatskola::Application.routes.draw do resources :posts get "admin/rakstu_red" get "home/par_skolu" get "home/personals" get "home/kontakti" get "home/pers_pieeja" get "home/galerijas" get "home/index" root :to =&gt; 'home#index' </code></pre> <p>posts.controller.rb destroy section:</p> <pre><code>def destroy @post = Post.find(params[:id]) @post.destroy respond_to do |format| format.html { redirect_to posts_url } format.json { head :no_content } end end </code></pre> <p>application.js:</p> <pre><code>// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // //= require jquery //= require jquery_ujs //= require_tree . </code></pre> <p>layout head:</p> <pre><code>&lt;head&gt; &lt;title&gt;Līvu pamatskola&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;%= stylesheet_link_tag 'style' %&gt; &lt;%= javascript_include_tag :defaults %&gt; &lt;%= csrf_meta_tag %&gt; &lt;/head&gt; </code></pre> <p><strong>SOLVED:</strong></p> <p>Found solution on this post: <a href="https://stackoverflow.com/questions/8726534/rails-3-1-link-to-not-showing-confirmation-or-destroying-properly">Rails 3.1 link_to not showing confirmation or destroying properly</a></p> <p>Anyway, thank you guys for helping!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload