Try ActiveRecord Query Trace

see...

https://github.com/ruckus/active-record-query-trace


I would suggest setting the level to :full or :rails like so, in case the bug 
comes from a Gem or Rails itself. 


ActiveRecordQueryTrace.level = :full

or 

ActiveRecordQueryTrace.level = :rails
(which is NOT the default)


Also try adjusting the lines setting to something that will show you the full 
trace, sometimes 25 or 100 or even 200 if your stack level is very deep. (But 
with 200 line stacktrace, it makes it harder to read, so you have to find the 
right balance)

You are looking for a ruby crash within the transaction itself, which would 
then cause the transaction to be rolled back. 

-Jason





> On May 3, 2017, at 11:35 PM, fugee ohu <[email protected]> wrote:
> 
> 
> 
> On Wednesday, May 3, 2017 at 9:44:06 PM UTC-4, Walter Lee Davis wrote:
> 
> > On May 3, 2017, at 9:07 PM, fugee ohu <[email protected] <javascript:>> 
> > wrote: 
> > 
> > 
> > 
> > On Wednesday, May 3, 2017 at 8:04:29 PM UTC-4, Edsil Basadre wrote: 
> > Sorry! Your question is quite vague. What did you do? You manually run a 
> > select query but then it rollback or you did a request in which it runs the 
> > select query then it rollback? please make the question more clear and if 
> > you can provide more error details. 
> > 
> > On Thu, 4 May 2017 at 7:37 AM, fugue ohu <[email protected] <>> wrote: 
> > When I run the select that rolls back in mysql there's no problem How can I 
> > debug this? 
> > 
> > Started POST "/artist/14/tour/3/press_releases/new" for 127.0.0.1 at 
> > 2017-05-03 19:08:27 -0400 
> > Processing by UserPressReleasesController#tour_create as HTML 
> >   Parameters: 
> > {"authenticity_token"=>"J/ZFBljt2V9q+yEV78t+L9BOjEkqpWHyFx29HSPdB0+/PKX7s4bxLhzcoP4mtepmoKJ2NY4JKCIOcfhJBQAMXg==",
> >  "artist_id"=>"14", "tour_id"=>"3"} 
> >   [1m [36mUser Load (2.0ms) [0m  [1m [34mSELECT  `users`.* FROM `users` 
> > WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1 [0m 
> >   [1m [36mArtist Load (1.9ms) [0m  [1m [34mSELECT  `artists`.* FROM 
> > `artists` WHERE `artists`.`id` = 14 LIMIT 1 [0m 
> >   [1m [36mTour Load (1.4ms) [0m  [1m [34mSELECT  `tours`.* FROM `tours` 
> > WHERE `tours`.`id` = 3 LIMIT 1 [0m 
> >   [1m [35m (0.6ms) [0m  [1m [35mBEGIN [0m 
> >   [1m [35m (3.0ms) [0m  [1m [31mROLLBACK [0m 
> > 
> > -- 
> > 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 [email protected] <>. 
> > To post to this group, send email to [email protected] <>. 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/rubyonrails-talk/0d6c0119-f666-4d8f-9ece-d2476e36dfe6%40googlegroups.com
> >  
> > <https://groups.google.com/d/msgid/rubyonrails-talk/0d6c0119-f666-4d8f-9ece-d2476e36dfe6%40googlegroups.com>.
> >  
> > For more options, visit https://groups.google.com/d/opto 
> > <https://groups.google.com/d/opto> 
> > 
> > As you can see the log begins with a post request and you can see the 
> > params list Of course there's an associated controller action but I don't 
> > know why the rollback 
> > 
> 
> I am not clear why you are using POST to load a /new path. Those are usually 
> done with GET. You would POST from that form to the collection (the create 
> verb), and after that, you would GET the form for the persisted object and 
> PATCH to it to update it. I would expect this action (creating a press 
> release for artist 14 and tour 3) to look like this: POST 
> /artist/14/tours/3/press_releases. It would hit the 
> press_releases_controller.rb on the #create verb (never the #new). The fact 
> that the method is #tour_create is surprising, since you already have a tour 
> persisted (id 4). Any further things you might do to that tour would update 
> it, and would go through the tours_controller.rb, hitting the #update method, 
> not the press_releases_controller. 
> 
> I'm scared to ask, but what does your routes.rb file look like? 
> 
> Without changing anything else right now, inside your mis-named tour_create 
> method, add a line that looks like this, after any line that includes 
> @press_release.save 
> 
>     Rails.logger.info <http://rails.logger.info/> 
> @press_release.errors.inspect 
> 
> That should give you a concise block of output, which may end in the human 
> readable errors on that object in a hash syntax. See what that looks like, 
> and if it gives you any clue about why the attempt to save rolled back. 
> 
> Also, have you started and finished the Michael Hartl Rails tutorial (free to 
> use on line at https://railstutorial.org <https://railstutorial.org/>)? This, 
> and a lot of other questions you have asked, make me think the answer is no. 
> Working all the way through that tutorial is a great way to familiarize 
> yourself with the basics of Rails development, including how to debug a 
> problem when it happens. The benefit to this is so great that we pay new 
> hires to do it at UPenn. 
> 
> Walter 
> 
> > -- 
> > 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 [email protected] <javascript:>. 
> > To post to this group, send email to [email protected] 
> > <javascript:>. 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/rubyonrails-talk/1b625052-81a0-4ed5-9ddf-a0561a2f889d%40googlegroups.com
> >  
> > <https://groups.google.com/d/msgid/rubyonrails-talk/1b625052-81a0-4ed5-9ddf-a0561a2f889d%40googlegroups.com>.
> >  
> > For more options, visit https://groups.google.com/d/optout 
> > <https://groups.google.com/d/optout>. 
> 
> 
> I guess I should mention I'm calling it from the tour show page without a 
> form, just like this
> <%= link_to 'Create this press release', 
> new_user_artist_tour_press_release_path(@artist.id, @tour.id), { method: 
> :post } %>
> That's the route to user_press_releases#tour_create
> 
> -- 
> 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 [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/57b824d0-7695-4b2d-b49a-606797711d27%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/rubyonrails-talk/57b824d0-7695-4b2d-b49a-606797711d27%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

----

Jason Fleetwood-Boldt
[email protected]
http://www.jasonfleetwoodboldt.com/writing

If you'd like to reply by encrypted email you can find my public key on 
jasonfleetwoodboldt.com <http://jasonfleetwoodboldt.com/> (more about setting 
GPG: https://gpgtools.org) 

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/848EBD3F-E727-4F60-9029-A298D23BEC1B%40datatravels.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to