Unable to delete post in sample blog application

48 views
Skip to first unread message

Peter Heylin

unread,
Mar 31, 2014, 12:02:09 PM3/31/14
to rubyonra...@googlegroups.com
Hi All,

I am new to RoR and I am writing a small blog application. I have added a Destroy / Delete link to the post index, but when I click this delete link the show action is fired. The log seems to confirm this: 

Started GET "/posts/2" for xxx.xxx.xxx.xxx at 2014-03-31 15:51:03 +0000
Processing by PostsController#show as HTML
  Parameters: {"id"=>"2"}
  Post Load (0.1ms)  SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1  [["id", "2"]]
  Comment Load (0.1ms)  SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ?  [["post_id", 2]]
  Rendered posts/show.html.erb within layouts/application (9.0ms)
Completed 200 OK in 120ms (Views: 117.3ms | ActiveRecord: 0.2ms)

My destroy method in the controller is: 

def destroy
    @post = Post.find(params[:id])
    @post.destroy

    redirect_to posts_path
end


The code in the index view is: 

       <td><%= link_to 'Destroy', post, method: :delete, data: {confirm: 'Are you sure?'}  %></td>

Would anyone have any idea what I might be missing here? 

Any help appreciated

Peter

Claudiu Clau

unread,
Mar 31, 2014, 12:12:41 PM3/31/14
to rubyonra...@googlegroups.com
I think here is the error:        <td><%= link_to 'Destroy', post, method: :delete, data: {confirm: 'Are you sure?'}  %></td>
= link_to 'Destroy', post_path(post), bla bla bla

Abdulsattar Mohammed

unread,
Mar 31, 2014, 12:24:26 PM3/31/14
to rubyonra...@googlegroups.com
Check if jquery-ujs is being loaded properly. I'd wager, your "Are you sure?" confirmation isn't even popping up.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e765b1b0-b7d5-4038-92c1-e6f6c0122c59%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards,
Abdulsattar Mohammed

Peter Heylin

unread,
Mar 31, 2014, 12:32:33 PM3/31/14
to rubyonra...@googlegroups.com
Thanks for the replies. 

@Claudiu I have fixed the link you mentioned and the app is doing the same thing. The show action is being fired when I click the Delete link

@Abdulsattar how I can I check if jquery-ujs is being loaded properly. The confirmation is not popping up. What change might be required to fix this? 

Thanks 

Peter

Peter Heylin

unread,
Mar 31, 2014, 12:39:34 PM3/31/14
to rubyonra...@googlegroups.com
Thanks for the replies. 

@Claudiu I have fixed the link you mentioned and the app is doing the same thing. The show action is being fired when I click the Delete link

@Abdulsattar how I can I check if jquery-ujs is being loaded properly. The confirmation is not popping up. What change might be required to fix this? 

Thanks 

Peter


On Monday, 31 March 2014 17:02:09 UTC+1, Peter Heylin wrote:

Abdulsattar Mohammed

unread,
Mar 31, 2014, 1:07:08 PM3/31/14
to rubyonra...@googlegroups.com
@Peter Heylin Check the console if any there are any javascript errors. And view page source, to see if jquery-ujs is being loaded. If it's not add it in the application.js as manifest.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Peter Heylin

unread,
Apr 1, 2014, 3:36:13 AM4/1/14
to rubyonra...@googlegroups.com
@Abdulsattar Mohammed, 

There are no javascript errors in the console and jquery-ujs appears to be loaded (see head of page source below). 

<head>
<title>Blog</title>
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/comments.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/posts.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/welcome.css?body=1" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/comments.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/posts.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/welcome.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="sTwrvSyBQ0rGRescsUYaL8JJ9LLcUfkOP6JMGcXiccw=" name="csrf-token" />
</head>

I have also checked to make sure the issue isn't something as small as a popup blocker. 

Thanks,

Peter


On Monday, 31 March 2014 17:02:09 UTC+1, Peter Heylin wrote:

mike2r

unread,
Apr 1, 2014, 10:43:39 AM4/1/14
to rubyonra...@googlegroups.com
The format of your link looks fine, I have to agree this looks like a javascript issue.  When you say, "no javascript errors in the console", what console are you looking at?  Javascript errors would appear in the browser.  If you use Firefox, Firebug is a great tool for this.  If you use Safari, in Preferences > Advanced check the box "Show Develop menu in menu bar".  If you use Chrome, there are similar tools under View > Developer.  Any of these tools will allow you to view any javascript errors.  If you use Internet Explorer, sorry I can't help you.  I'm sure someone else can.

It does look like you have the jquery_ujs file properly loading. You might want to check a couple of things.  First, make sure the jquery_ujs gem is current.  Second, make sure you do NOT have a jquery_ujs.js file in the app/assets/javascripts folder.  You want this to be supplied by the gem.   

Wei Xia

unread,
Apr 3, 2014, 2:45:14 AM4/3/14
to rubyonra...@googlegroups.com
link_to 'Destroy', post_path(post), bla bla bla Gel de sílice de tipo B
/A/C
http://es.silicon-gel-china.com

--
Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages