Ruby on Rails Thursday, January 31, 2019

I have a Rails app, made 10 years back in 2009 with following version:
rails version = 2.0.2 
ruby version = 1.8.7
Database = PostgreSQL

Now what steps I should adopt in order to upgrade it to latest version of ruby and rails i.e.,
rails version = 5.2
ruby version = 2.6
Database = PostgreSQL

As per up-gradation rule here(https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html), I need to start up-gradation one by one version gradually like,
2.x to 3.x
3.x to 4.x 
4.x to 5.x

My question here is, 
Is there any other way to directly update it from 2.x to 5.x?

Note: I can develop it by scratch but my client not agree on that, they just asking for update in existing app not build from scratch in latest version of Ruby on Rails.

Kindly provide your thoughts.

Thanks 

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fa59e599-44bc-4d30-91c6-a048edb9e2ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

> On Jan 31, 2019, at 4:57 PM, fugee ohu <fugee279@gmail.com> wrote:
>
>
>
> On Thursday, January 31, 2019 at 4:38:52 PM UTC-5, Walter Lee Davis wrote:
>
> > On Jan 31, 2019, at 3:50 PM, fugee ohu <fuge...@gmail.com> wrote:
> >
> > I had to remove a validation on the :name column because my PictureUploader which uses Carrierwave is mounted on that column
> > mount_uploader :name, PictureUploader
> > This causes validation
> > validates :name, presence: true
> > to cause rows in pictures to be invalid for blank :name even though the name, just a filename, is in the database for that column
>
> CarrierWave overloads the accessor for the attachment column to respond with the entire uploader model object. This is normal for CarrierWave.
>
> There are other attachment systems (I'm fond of Shrine) that use a different, less-surprising approach. In Shrine, you would have a column called picture_data and an attachment called picture. That way you can keep the difference between db column and virtual object separate.
>
> 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 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/8f78599a-5e59-43e1-8d1e-ec38e897c68d%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> If the uploader's mounted on that column do I still have to validate it ?
>

I haven't used Carrierwave in a number of years, but I think that it implements some validators of its own. You should investigate the documentation for CW.

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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/B29EF39A-C1C0-4170-9D26-0D58EE445931%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Thursday, January 31, 2019 at 4:38:52 PM UTC-5, Walter Lee Davis wrote:

> On Jan 31, 2019, at 3:50 PM, fugee ohu <fuge...@gmail.com> wrote:
>
> I had to remove a validation on the :name column because my PictureUploader which uses Carrierwave is mounted on that column
>  mount_uploader :name, PictureUploader
> This causes validation
> validates :name, presence: true
> to cause rows in pictures to be invalid for blank :name even though the name, just a filename, is in the database for that column

CarrierWave overloads the accessor for the attachment column to respond with the entire uploader model object. This is normal for CarrierWave.

There are other attachment systems (I'm fond of Shrine) that use a different, less-surprising approach. In Shrine, you would have a column called picture_data and an attachment called picture. That way you can keep the difference between db column and virtual object separate.

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 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/8f78599a-5e59-43e1-8d1e-ec38e897c68d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

 If the uploader's mounted on that column do I still have to validate it ?

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/822db871-615d-4afa-94ad-ea0a3c5b001e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

> On Jan 31, 2019, at 3:50 PM, fugee ohu <fugee279@gmail.com> wrote:
>
> I had to remove a validation on the :name column because my PictureUploader which uses Carrierwave is mounted on that column
> mount_uploader :name, PictureUploader
> This causes validation
> validates :name, presence: true
> to cause rows in pictures to be invalid for blank :name even though the name, just a filename, is in the database for that column

CarrierWave overloads the accessor for the attachment column to respond with the entire uploader model object. This is normal for CarrierWave.

There are other attachment systems (I'm fond of Shrine) that use a different, less-surprising approach. In Shrine, you would have a column called picture_data and an attachment called picture. That way you can keep the difference between db column and virtual object separate.

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 rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8f78599a-5e59-43e1-8d1e-ec38e897c68d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6A2E2DCB-4B5C-465A-9952-1E37FC4370D7%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I had to remove a validation on the :name column because my PictureUploader which uses Carrierwave is mounted on that column
 mount_uploader :name, PictureUploader
This causes validation
validates :name, presence: true
to cause rows in pictures to be invalid for blank :name even though the name, just a filename, is in the database for that column

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8f78599a-5e59-43e1-8d1e-ec38e897c68d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Rails complains :name is blank for rows in my Picture model because it seems because Carrierwave uploader is mounted on that column If I grab a row into an object and accesss object.name I get the Carrierwave object returned instead of the :name, filename.jpg, that mysql database standalone shows so object.valid? returns false

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/38f8c2fe-f862-460b-ab2b-eff27b116166%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

rails complains :name is blank and so the record is invalid


p=Picture.first
p
=>2.3.3 :014 > p
 => #<Picture id: 2, comment: "Henry McCarty", imageable_id: 1, imageable_type: "Photo", content_type: nil, created_at: "2018-09-20 02:08:02", updated_at: "2018-10-25 13:41:24", name: "Billy_the_Kid_Ferrotype.jpg", designation: nil, blog_id: nil, caption: "Unretouched original ferrotype of Bonney c. 1880", details: "Henry McCarty", copyright_claim: false, source_page: nil, slug: nil> 
2.3.3 :017 > p.id
 => 2 
2.3.3 :018 > p.comment
 => "Henry McCarty" 
2.3.3 :019 > p.name
 => #<PictureUploader:0x00564c8171dd00 @model=#<Picture id: 2, comment: "Henry McCarty", imageable_id: 1, imageable_type: "Photo", content_type: nil, created_at: "2018-09-20 02:08:02", updated_at: "2018-10-25 13:41:24", name: "Billy_the_Kid_Ferrotype.jpg", designation: nil, blog_id: nil, caption: "Unretouched original ferrotype of Bonney c. 1880", details: "Henry McCarty", copyright_claim: false, source_page: nil, slug: nil>, @mounted_as=:name, @storage=#<CarrierWave::Storage::File:0x00564c8171d710 @uploader=#<PictureUploader:0x00564c8171dd00 ...>>, @file=#<CarrierWave::SanitizedFile:0x00564c8171d288 @file="/home/fugee/data/websites/thekidslepthere/public/images/Billy_the_Kid_Ferrotype.jpg", @original_filename=nil, @content_type=nil>, @versions={:thumb=>#<PictureUploader::Uploader47443268402420:0x00564c8171d238 @model=#<Picture id: 2, comment: "Henry McCarty", imageable_id: 1, imageable_type: "Photo", content_type: nil, created_at: "2018-09-20 02:08:02", updated_at: "2018-10-25 13:41:24", name: "Billy_the_Kid_Ferrotype.jpg", designation: nil, blog_id: nil, caption: "Unretouched original ferrotype of Bonney c. 1880", details: "Henry McCarty", copyright_claim: false, source_page: nil, slug: nil>, @mounted_as=:name, @parent_version=#<PictureUploader:0x00564c8171dd00 ...>, @storage=#<CarrierWave::Storage::File:0x00564c8171d198 @uploader=#<PictureUploader::Uploader47443268402420:0x00564c8171d238 ...>>, @file=#<CarrierWave::SanitizedFile:0x00564c8171cce8 @file="/home/fugee/data/websites/thekidslepthere/public/images/thumb_Billy_the_Kid_Ferrotype.jpg", @original_filename=nil, @content_type=nil>, @versions={}>}>

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/568eab6e-91ea-43a3-9b8d-06e809a94319%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

My Picture model has a :name column which is just string but what it stores looks like an object Rails says the row has an error :name is blank Do I have this model setup right? 

p=Picture.first
p.valid?
=> false
p.errors
 => #<ActiveModel::Errors:0x00564c8503f700 @base=#<Picture id: 2, comment: "Henry McCarty", imageable_id: 1, imageable_type: "Photo", content_type: nil, created_at: "2018-09-20 02:08:02", updated_at: "2018-10-25 13:41:24", name: "Billy_the_Kid_Ferrotype.jpg", designation: nil, blog_id: nil, caption: "Unretouched original ferrotype of Bonney c. 1880", details: "Henry McCarty", copyright_claim: false, source_page: nil, slug: nil>, @messages={:name=>["translation missing: en-US.activerecord.errors.models.picture.attributes.name.blank"]}, @details={:name=>[{:error=>:blank}]}> 

p.name

=> #<PictureUploader:0x00564c8171dd00 @model=#<Picture id: 2, comment: "Henry McCarty", imageable_id: 1, imageable_type: "Photo", content_type: nil, created_at: "2018-09-20 02:08:02", updated_at: "2018-10-25 13:41:24", name: "Billy_the_Kid_Ferrotype.jpg", designation: nil, blog_id: nil, caption: "Unretouched original ferrotype of Bonney c. 1880", details: "Henry McCarty", copyright_claim: false, source_page: nil, slug: nil>, @mounted_as=:name, @storage=#<CarrierWave::Storage::File:0x00564c8171d710 @uploader=#<PictureUploader:0x00564c8171dd00 ...>>, @file=#<CarrierWave::SanitizedFile:0x00564c8171d288 @file="/home/fugee/data/websites/thekidslepthere/public/images/Billy_the_Kid_Ferrotype.jpg", @original_filename=nil, @content_type=nil>, @versions={:thumb=>#<PictureUploader::Uploader47443268402420:0x00564c8171d238 @model=#<Picture id: 2, comment: "Henry McCarty", imageable_id: 1, imageable_type: "Photo", content_type: nil, created_at: "2018-09-20 02:08:02", updated_at: "2018-10-25 13:41:24", name: "Billy_the_Kid_Ferrotype.jpg", designation: nil, blog_id: nil, caption: "Unretouched original ferrotype of Bonney c. 1880", details: "Henry McCarty", copyright_claim: false, source_page: nil, slug: nil>, @mounted_as=:name, @parent_version=#<PictureUploader:0x00564c8171dd00 ...>, @storage=#<CarrierWave::Storage::File:0x00564c8171d198 @uploader=#<PictureUploader::Uploader47443268402420:0x00564c8171d238 ...>>, @file=#<CarrierWave::SanitizedFile:0x00564c8171cce8 @file="/home/fugee/data/websites/thekidslepthere/public/images/thumb_Billy_the_Kid_Ferrotype.jpg", @original_filename=nil, @content_type=nil>, @versions={}>}> 

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/072a0839-d57f-43b7-a92b-a7da15dc4429%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Tuesday, January 29, 2019 at 11:12:29 PM UTC-5, Walter Lee Davis wrote:

> On Jan 29, 2019, at 9:55 PM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Tuesday, January 29, 2019 at 8:31:18 AM UTC-5, Walter Lee Davis wrote:
>
> > On Jan 28, 2019, at 8:47 PM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Monday, January 28, 2019 at 10:23:43 AM UTC-5, Walter Lee Davis wrote:
> >
> > > On Jan 27, 2019, at 8:34 PM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > >
> > >
> > > On Sunday, January 27, 2019 at 5:31:11 PM UTC-5, Walter Lee Davis wrote:
> > >
> > > > On Jan 27, 2019, at 5:01 PM, fugee ohu <fuge...@gmail.com> wrote:
> > > >
> > > >
> > > >
> > > > On Sunday, January 27, 2019 at 4:47:48 PM UTC-5, Walter Lee Davis wrote:
> > > >
> > > > > On Jan 27, 2019, at 4:11 PM, fugee ohu <fuge...@gmail.com> wrote:
> > > > >
> > > > >
> > > > >
> > > > > On Sunday, January 27, 2019 at 2:43:46 PM UTC-5, Walter Lee Davis wrote:
> > > > >
> > > > > > On Jan 27, 2019, at 7:35 AM, fugee ohu <fuge...@gmail.com> wrote:
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Sunday, January 27, 2019 at 12:24:25 AM UTC-5, Walter Lee Davis wrote:
> > > > > >
> > > > > > > On Jan 26, 2019, at 11:49 PM, fugee ohu <fuge...@gmail.com> wrote:
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On Saturday, January 26, 2019 at 6:58:17 PM UTC-5, Walter Lee Davis wrote:
> > > > > > >
> > > > > > > > On Jan 26, 2019, at 5:27 PM, fugee ohu <fuge...@gmail.com> wrote:
> > > > > > > >
> > > > > > > > TypeError: no implicit conversion of Symbol into Integer
> > > > > > > > from app/models/press_release.rb:17:in `truncated_headline'
> > > > > > > >
> > > > > > > >
> > > > > > > > class PressRelease < ApplicationRecord
> > > > > > > >
> > > > > > > >   extend FriendlyId
> > > > > > > >   friendly_id :truncated_headline, use: :slugged
> > > > > > > >
> > > > > > > >          
> > > > > > > >   def truncated_headline
> > > > > > > >   # cut off at 200 characters, without an ellipsis
> > > > > > > >         headline.truncate(255, '')
> > > > > > > >   end
> > > > > > > >
> > > > > > >
> > > > > > > Aha. truncate takes named arguments past the first one. The correct signature is
> > > > > > >
> > > > > > > headline.truncate(255, omission: '')
> > > > > > >
> > > > > > > This should work.
> > > > > > >
> > > > > > > Walter
> > > > > > >
> > > > > > > Still rolling back
> > > > > > >
> > > > > > >
> > > > > >
> > > > > > Show me an example from your development console. Copy and paste. Make sure that you include the part where we can see the parameters being passed into your controller. I suspect that you are trying to pass a type = 'admin' parameter somewhere, that's what the error looked like earlier. Type columns in polymorphic relationships must be passed a valid constant name, which will begin with an upper-case letter. If there is a model in that relationship named admin, you would pass Admin rather than admin.
> > > > > >
> > > > > > Walter
> > > > > >
> > > > > >
> > > > > >  Loading development environment (Rails 5.2.0)
> > > > > > 2.3.3 :001 > PressRelease.find_each(&:save)
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (24.1ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Load (53.8ms)  SELECT  `press_releases`.* FROM `press_releases` ORDER BY `press_releases`.`id` ASC LIMIT 1000
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (7.1ms)  BEGIN
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Exists (9.4ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 2 AND `press_releases`.`slug` = 'outskirts-of-love-is-available-now-some-autographed-copies-remain' LIMIT 1
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (7.9ms)  ROLLBACK
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (5.6ms)  BEGIN
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Exists (9.6ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 3 AND `press_releases`.`slug` = 'shemekia-copeland-to-appear-in-new-york-and-teaneck' LIMIT 1
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (6.3ms)  ROLLBACK
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (6.0ms)  BEGIN
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Exists (12.7ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 5 AND `press_releases`.`slug` = 'al-basile-creates-new-roots-music-masterpiece-with-b-s-expression-due-september-18-on-sweetspot-records-latest-release-is-most-fully-realized-album-yet' LIMIT 1
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (8.1ms)  ROLLBACK
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (6.0ms)  BEGIN
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Exists (8.9ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 6 AND `press_releases`.`slug` = 'new-cd-from-british-blues-godfather-john-mayall-find-a-way-to-care-set-for-release-september-4th-on-forty-below-records-vinyl-lp-to-follow-in-fall' LIMIT 1
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (6.8ms)  ROLLBACK
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >
> > > > > >
> > > > >
> > > > > Okay, since you're not in the development console, and aren't handling a PUT or PATCH, you don't have parameters to look at here. So this is less useful than I had hoped. Please answer these questions, preferably inline, so I don't have to play hunt-and-peck to figure this out.
> > > > >
> > > > > 1. When you added FriendlyId to your app, did you use the built-in generator to add the friendly_id_slugs table to your app?
> > > > >
> > > > > 2. After you added gem 'friendly_id' to your Gemfile, and ran bundle install, did you at any point after that do anything that caused the friendly_id gem to upgrade to a newer version? Hint: look through the git history on your Gemfile.lock file, and look for any (upward, I'm guessing) movement of the version number of the friendly_id gem. The line you are looking at will be the one that reads something like
> > > > >
> > > > >   friendly_id (5.2.5)
> > > > >
> > > > > with nothing else on the same line. Any other reference to friendly_id will be in dependencies, not the actual version of the gem that your app is loading and running.
> > > > >
> > > > > 3. What happens if you change &:save to &:save! (with a bang!) in order to die spectacularly and throw a visible error?
> > > > >
> > > > > 4. What happens if you unroll the Symbol-to-Proc sugar into its long-hand equivalent? Example:
> > > > >
> > > > > YourModel.find_each do |instance|
> > > > >   instance.save!
> > > > >   puts instance.errors.full_messages
> > > > > end
> > > > >
> > > > > That should die after the first model with errors, and throw out a more useful error message than ROLLBACK.
> > > > >
> > > > > If the answer to #2 is Yes, then you will probably need to read through the upgrade instructions on the FriendlyId project README on GitHub, and figure out what you didn't do. That's not likely to be the problem, but I put it out there because this project has had some tectonic shifts in its schema, and all of them are covered with extra migrations that you optionally run when you update. Missing any of these could cause the whole thing to fail. But that's only likely if you started with FriendlyId a while ago, and then did something unrelated with Bundler that caused this gem to upgrade further than you were expecting. Particularly if you see that the version has changed in the major number, like from 3.x.x to 4.x.x, that's when you would want to be very careful to check those instructions.
> > > > >
> > > > > Walter
> > > > >
> > > > >
> > > > >  ActiveRecord::RecordInvalid: translation missing: en-US.activerecord.errors.messages.record_invalid
> > > > >         from (irb):1
> > > > >
> > > >
> > > > This is interesting. Try removing the .full_messages part and run this again. You have an invalid record, which means it can't be saved. You have to figure out what the error is. What validations do you have on the object? What validations do you have on the related models? What requirements are you missing? That's where your problem is -- this has zero to do with friendly_id.
> > > >
> > > > 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 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/0055fa7d-84e6-4082-83ca-f9e18aeb78ad%40googlegroups.com.
> > > > > For more options, visit https://groups.google.com/d/optout.
> > > >
> > > >
> > > >  class PressRelease < ApplicationRecord
> > > >
> > > >   extend FriendlyId
> > > >   friendly_id :truncated_headline, use: :slugged
> > > >   belongs_to :poster, polymorphic: true
> > > >   attr_accessor :club_id
> > > >   attr_accessor :festival_id
> > > >   attr_accessor :user_venue_id
> > > >   has_many :pictures, as: :imageable
> > > >
> > > >   def self.search(search)
> > > >     where("headline LIKE ? OR storyline LIKE ? OR publicist LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
> > > >   end
> > > >  
> > > >   def truncated_headline
> > > >   # cut off at 200 characters, without an ellipsis
> > > >         headline.truncate(255, omission: '')
> > > >   end
> > > >  
> > > >   validates :publicist, :headline, :storyline, :dateline, :genre_id, :presence => true
> > > >   validates :venue_state,  :presence => true, :if =>  Proc.new { |e| e.venue_country == "US" && !(e.press_release_type="tour") }
> > > >   validates :venue_state,  :presence => false, :if =>  Proc.new { |e| e.venue_country != "US" }
> > > >   validates :venue, :venue_country, :venue_city, :venue_address, :showdate, :showtime,  :presence => true, :unless =>  Proc.new { |e| e.poster_type == 'Admin' || (e.press_release_type="tour") }
> > > >   validates :showdate,  :presence => true, :if =>  Proc.new { |e| e.club_id.present? || (e.festival_id.present?) || (e.user_venue_id.present?) || (e.venue_name.present?) }
> > > >   validates :showdate,   :date => { :after => Time.now + 2.hour }, :if =>  Proc.new { |e| e.user_id.present? }
> > > >   validates :image_url, allow_blank: true,  format: {with: %r{\.(gif|jpg|png)\Z}i, message: 'must be a URL for GIF, JPG or PNG image.'}
> > > >   validates :showdate,  :presence => true, :if =>  Proc.new { |e| e.user_id.present? }
> > > >  
> > > >  
> > > >   VENUE_STATE_TYPES =
> > > >   [
> > > >     ['Alabama', 'AL'],
> > > >     ...
> > > >     ['Wyoming', 'WY']
> > > >   ]
> > > >
> > > >
> > > > end
> > > >
> > > >
> > >
> > > Interesting, but meaningless without seeing what the error is when you try to save a record. Try opening up this application in console, selecting the first record in the press releases, and saving it. See what you get in the console error message.
> > >
> > > rails c development
> > >
> > > pr = PressRelease.first
> > > pr.touch
> > > pr.save!
> > >
> > > What happens here?
> > >
> > > All the console stuff you have been showing so far appears to be in production, and the errors don't include a stack trace or any detail besides the database ROLLBACK.
> > >
> > > Try to repeat the error in development, or set your log level to info in production and try to repeat it there.
> > >
> > > 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 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/1b6f26b5-8b6a-4e97-8467-261ea7f2e489%40googlegroups.com.
> > > > For more options, visit https://groups.google.com/d/optout.
> > >
> > >
> > >  2.3.3 :003 > pr.save
> > >   Query Trace > (irb):3:in `irb_binding'
> > >    (7.1ms)  BEGIN
> > >   Query Trace > (irb):3:in `irb_binding'
> > >   PressRelease Exists (11.8ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 2 AND `press_releases`.`slug` = 'outskirts-of-love-is-available-now-some-autographed-copies-remain' LIMIT 1
> > >   Query Trace > (irb):3:in `irb_binding'
> > >    (6.5ms)  ROLLBACK
> > >  => false
> > >
> >
> > Try this:
> >
> > PressRelease.update_all slug: nil
> >
> > Then try running your &:save! again.
> >
> > Walter
> >
> > Still getting ROLLBACK's
> >
>
> p = PressRelease.first
>
> p.valid?
>
> p.errors.inspect
>
> What do you see?
>
> Walter
>
>
>
>
>  "#<ActiveModel::Errors:0x00557931a9a9e8 @base=#<PressRelease id: 2, publicist: \"Alligator Records\", headline: \"OUTSKIRTS OF LOVE Is Available Now! Some Autograph...\", storyline: \"Alligator Records News, Blues & More \\r\\nOUTSKIRTS O...\", dateline: \"2015-09-23 00:00:00\", created_at: \"2015-09-23 22:57:00\", updated_at: \"2019-01-28 01:32:11\", image_url: \"9.png\", storyline_html_tail: nil, user_id: nil, artist_id: nil, venue_name: nil, venue_address: nil, venue_phone: nil, showdate: nil, showtime: nil, showtime_second: nil, poster_type: nil, poster_id: nil, additional_info: nil, venue_country: nil, venue_state: nil, venue_city: nil, genre_id: 1, tour_id: nil, press_release_type: \"tour\", venue_id: nil, venue_type: nil, venue_address0: nil, postal_code: nil, venue_f_address: nil, venue_postal_code: nil, top_story: nil, slug: nil>, @messages={:poster=>[\"translation missing: en-US.activerecord.errors.models.press_release.attributes.poster.required\"]}, @details={:poster=>[{:error=>:blank}]}>"
>

Great. Now you have your answer. The poster is required, and not valued, so the save won't work. Figure out why the poster is required, and you will fix your application. To be clear, this has nothing at all to do with FriendlyId.

Walter


What about the through models in has_many_through relationships where i've applied friendly_id to the outside models Should I setup the through models to use friendly_id

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c94fa4b4-5842-49f0-9dd7-e4a6914f4638%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Tuesday, January 29, 2019 at 11:12:29 PM UTC-5, Walter Lee Davis wrote:

> On Jan 29, 2019, at 9:55 PM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Tuesday, January 29, 2019 at 8:31:18 AM UTC-5, Walter Lee Davis wrote:
>
> > On Jan 28, 2019, at 8:47 PM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Monday, January 28, 2019 at 10:23:43 AM UTC-5, Walter Lee Davis wrote:
> >
> > > On Jan 27, 2019, at 8:34 PM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > >
> > >
> > > On Sunday, January 27, 2019 at 5:31:11 PM UTC-5, Walter Lee Davis wrote:
> > >
> > > > On Jan 27, 2019, at 5:01 PM, fugee ohu <fuge...@gmail.com> wrote:
> > > >
> > > >
> > > >
> > > > On Sunday, January 27, 2019 at 4:47:48 PM UTC-5, Walter Lee Davis wrote:
> > > >
> > > > > On Jan 27, 2019, at 4:11 PM, fugee ohu <fuge...@gmail.com> wrote:
> > > > >
> > > > >
> > > > >
> > > > > On Sunday, January 27, 2019 at 2:43:46 PM UTC-5, Walter Lee Davis wrote:
> > > > >
> > > > > > On Jan 27, 2019, at 7:35 AM, fugee ohu <fuge...@gmail.com> wrote:
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Sunday, January 27, 2019 at 12:24:25 AM UTC-5, Walter Lee Davis wrote:
> > > > > >
> > > > > > > On Jan 26, 2019, at 11:49 PM, fugee ohu <fuge...@gmail.com> wrote:
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On Saturday, January 26, 2019 at 6:58:17 PM UTC-5, Walter Lee Davis wrote:
> > > > > > >
> > > > > > > > On Jan 26, 2019, at 5:27 PM, fugee ohu <fuge...@gmail.com> wrote:
> > > > > > > >
> > > > > > > > TypeError: no implicit conversion of Symbol into Integer
> > > > > > > > from app/models/press_release.rb:17:in `truncated_headline'
> > > > > > > >
> > > > > > > >
> > > > > > > > class PressRelease < ApplicationRecord
> > > > > > > >
> > > > > > > >   extend FriendlyId
> > > > > > > >   friendly_id :truncated_headline, use: :slugged
> > > > > > > >
> > > > > > > >          
> > > > > > > >   def truncated_headline
> > > > > > > >   # cut off at 200 characters, without an ellipsis
> > > > > > > >         headline.truncate(255, '')
> > > > > > > >   end
> > > > > > > >
> > > > > > >
> > > > > > > Aha. truncate takes named arguments past the first one. The correct signature is
> > > > > > >
> > > > > > > headline.truncate(255, omission: '')
> > > > > > >
> > > > > > > This should work.
> > > > > > >
> > > > > > > Walter
> > > > > > >
> > > > > > > Still rolling back
> > > > > > >
> > > > > > >
> > > > > >
> > > > > > Show me an example from your development console. Copy and paste. Make sure that you include the part where we can see the parameters being passed into your controller. I suspect that you are trying to pass a type = 'admin' parameter somewhere, that's what the error looked like earlier. Type columns in polymorphic relationships must be passed a valid constant name, which will begin with an upper-case letter. If there is a model in that relationship named admin, you would pass Admin rather than admin.
> > > > > >
> > > > > > Walter
> > > > > >
> > > > > >
> > > > > >  Loading development environment (Rails 5.2.0)
> > > > > > 2.3.3 :001 > PressRelease.find_each(&:save)
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (24.1ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Load (53.8ms)  SELECT  `press_releases`.* FROM `press_releases` ORDER BY `press_releases`.`id` ASC LIMIT 1000
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (7.1ms)  BEGIN
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Exists (9.4ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 2 AND `press_releases`.`slug` = 'outskirts-of-love-is-available-now-some-autographed-copies-remain' LIMIT 1
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (7.9ms)  ROLLBACK
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (5.6ms)  BEGIN
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Exists (9.6ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 3 AND `press_releases`.`slug` = 'shemekia-copeland-to-appear-in-new-york-and-teaneck' LIMIT 1
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (6.3ms)  ROLLBACK
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (6.0ms)  BEGIN
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Exists (12.7ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 5 AND `press_releases`.`slug` = 'al-basile-creates-new-roots-music-masterpiece-with-b-s-expression-due-september-18-on-sweetspot-records-latest-release-is-most-fully-realized-album-yet' LIMIT 1
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (8.1ms)  ROLLBACK
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (6.0ms)  BEGIN
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >   PressRelease Exists (8.9ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 6 AND `press_releases`.`slug` = 'new-cd-from-british-blues-godfather-john-mayall-find-a-way-to-care-set-for-release-september-4th-on-forty-below-records-vinyl-lp-to-follow-in-fall' LIMIT 1
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >    (6.8ms)  ROLLBACK
> > > > > >   Query Trace > (irb):1:in `irb_binding'
> > > > > >
> > > > > >
> > > > >
> > > > > Okay, since you're not in the development console, and aren't handling a PUT or PATCH, you don't have parameters to look at here. So this is less useful than I had hoped. Please answer these questions, preferably inline, so I don't have to play hunt-and-peck to figure this out.
> > > > >
> > > > > 1. When you added FriendlyId to your app, did you use the built-in generator to add the friendly_id_slugs table to your app?
> > > > >
> > > > > 2. After you added gem 'friendly_id' to your Gemfile, and ran bundle install, did you at any point after that do anything that caused the friendly_id gem to upgrade to a newer version? Hint: look through the git history on your Gemfile.lock file, and look for any (upward, I'm guessing) movement of the version number of the friendly_id gem. The line you are looking at will be the one that reads something like
> > > > >
> > > > >   friendly_id (5.2.5)
> > > > >
> > > > > with nothing else on the same line. Any other reference to friendly_id will be in dependencies, not the actual version of the gem that your app is loading and running.
> > > > >
> > > > > 3. What happens if you change &:save to &:save! (with a bang!) in order to die spectacularly and throw a visible error?
> > > > >
> > > > > 4. What happens if you unroll the Symbol-to-Proc sugar into its long-hand equivalent? Example:
> > > > >
> > > > > YourModel.find_each do |instance|
> > > > >   instance.save!
> > > > >   puts instance.errors.full_messages
> > > > > end
> > > > >
> > > > > That should die after the first model with errors, and throw out a more useful error message than ROLLBACK.
> > > > >
> > > > > If the answer to #2 is Yes, then you will probably need to read through the upgrade instructions on the FriendlyId project README on GitHub, and figure out what you didn't do. That's not likely to be the problem, but I put it out there because this project has had some tectonic shifts in its schema, and all of them are covered with extra migrations that you optionally run when you update. Missing any of these could cause the whole thing to fail. But that's only likely if you started with FriendlyId a while ago, and then did something unrelated with Bundler that caused this gem to upgrade further than you were expecting. Particularly if you see that the version has changed in the major number, like from 3.x.x to 4.x.x, that's when you would want to be very careful to check those instructions.
> > > > >
> > > > > Walter
> > > > >
> > > > >
> > > > >  ActiveRecord::RecordInvalid: translation missing: en-US.activerecord.errors.messages.record_invalid
> > > > >         from (irb):1
> > > > >
> > > >
> > > > This is interesting. Try removing the .full_messages part and run this again. You have an invalid record, which means it can't be saved. You have to figure out what the error is. What validations do you have on the object? What validations do you have on the related models? What requirements are you missing? That's where your problem is -- this has zero to do with friendly_id.
> > > >
> > > > 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 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/0055fa7d-84e6-4082-83ca-f9e18aeb78ad%40googlegroups.com.
> > > > > For more options, visit https://groups.google.com/d/optout.
> > > >
> > > >
> > > >  class PressRelease < ApplicationRecord
> > > >
> > > >   extend FriendlyId
> > > >   friendly_id :truncated_headline, use: :slugged
> > > >   belongs_to :poster, polymorphic: true
> > > >   attr_accessor :club_id
> > > >   attr_accessor :festival_id
> > > >   attr_accessor :user_venue_id
> > > >   has_many :pictures, as: :imageable
> > > >
> > > >   def self.search(search)
> > > >     where("headline LIKE ? OR storyline LIKE ? OR publicist LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
> > > >   end
> > > >  
> > > >   def truncated_headline
> > > >   # cut off at 200 characters, without an ellipsis
> > > >         headline.truncate(255, omission: '')
> > > >   end
> > > >  
> > > >   validates :publicist, :headline, :storyline, :dateline, :genre_id, :presence => true
> > > >   validates :venue_state,  :presence => true, :if =>  Proc.new { |e| e.venue_country == "US" && !(e.press_release_type="tour") }
> > > >   validates :venue_state,  :presence => false, :if =>  Proc.new { |e| e.venue_country != "US" }
> > > >   validates :venue, :venue_country, :venue_city, :venue_address, :showdate, :showtime,  :presence => true, :unless =>  Proc.new { |e| e.poster_type == 'Admin' || (e.press_release_type="tour") }
> > > >   validates :showdate,  :presence => true, :if =>  Proc.new { |e| e.club_id.present? || (e.festival_id.present?) || (e.user_venue_id.present?) || (e.venue_name.present?) }
> > > >   validates :showdate,   :date => { :after => Time.now + 2.hour }, :if =>  Proc.new { |e| e.user_id.present? }
> > > >   validates :image_url, allow_blank: true,  format: {with: %r{\.(gif|jpg|png)\Z}i, message: 'must be a URL for GIF, JPG or PNG image.'}
> > > >   validates :showdate,  :presence => true, :if =>  Proc.new { |e| e.user_id.present? }
> > > >  
> > > >  
> > > >   VENUE_STATE_TYPES =
> > > >   [
> > > >     ['Alabama', 'AL'],
> > > >     ...
> > > >     ['Wyoming', 'WY']
> > > >   ]
> > > >
> > > >
> > > > end
> > > >
> > > >
> > >
> > > Interesting, but meaningless without seeing what the error is when you try to save a record. Try opening up this application in console, selecting the first record in the press releases, and saving it. See what you get in the console error message.
> > >
> > > rails c development
> > >
> > > pr = PressRelease.first
> > > pr.touch
> > > pr.save!
> > >
> > > What happens here?
> > >
> > > All the console stuff you have been showing so far appears to be in production, and the errors don't include a stack trace or any detail besides the database ROLLBACK.
> > >
> > > Try to repeat the error in development, or set your log level to info in production and try to repeat it there.
> > >
> > > 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 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/1b6f26b5-8b6a-4e97-8467-261ea7f2e489%40googlegroups.com.
> > > > For more options, visit https://groups.google.com/d/optout.
> > >
> > >
> > >  2.3.3 :003 > pr.save
> > >   Query Trace > (irb):3:in `irb_binding'
> > >    (7.1ms)  BEGIN
> > >   Query Trace > (irb):3:in `irb_binding'
> > >   PressRelease Exists (11.8ms)  SELECT  1 AS one FROM `press_releases` WHERE `press_releases`.`id` != 2 AND `press_releases`.`slug` = 'outskirts-of-love-is-available-now-some-autographed-copies-remain' LIMIT 1
> > >   Query Trace > (irb):3:in `irb_binding'
> > >    (6.5ms)  ROLLBACK
> > >  => false
> > >
> >
> > Try this:
> >
> > PressRelease.update_all slug: nil
> >
> > Then try running your &:save! again.
> >
> > Walter
> >
> > Still getting ROLLBACK's
> >
>
> p = PressRelease.first
>
> p.valid?
>
> p.errors.inspect
>
> What do you see?
>
> Walter
>
>
>
>
>  "#<ActiveModel::Errors:0x00557931a9a9e8 @base=#<PressRelease id: 2, publicist: \"Alligator Records\", headline: \"OUTSKIRTS OF LOVE Is Available Now! Some Autograph...\", storyline: \"Alligator Records News, Blues & More \\r\\nOUTSKIRTS O...\", dateline: \"2015-09-23 00:00:00\", created_at: \"2015-09-23 22:57:00\", updated_at: \"2019-01-28 01:32:11\", image_url: \"9.png\", storyline_html_tail: nil, user_id: nil, artist_id: nil, venue_name: nil, venue_address: nil, venue_phone: nil, showdate: nil, showtime: nil, showtime_second: nil, poster_type: nil, poster_id: nil, additional_info: nil, venue_country: nil, venue_state: nil, venue_city: nil, genre_id: 1, tour_id: nil, press_release_type: \"tour\", venue_id: nil, venue_type: nil, venue_address0: nil, postal_code: nil, venue_f_address: nil, venue_postal_code: nil, top_story: nil, slug: nil>, @messages={:poster=>[\"translation missing: en-US.activerecord.errors.models.press_release.attributes.poster.required\"]}, @details={:poster=>[{:error=>:blank}]}>"
>

Great. Now you have your answer. The poster is required, and not valued, so the save won't work. Figure out why the poster is required, and you will fix your application. To be clear, this has nothing at all to do with FriendlyId.

Walter


Having this problem on another database When I run errors on a row it says :name is blank but if I check the database I can't find any rows with null :name field, they all have values
 => #<ActiveModel::Errors:0x0055c65e1b4ef8 @base=#<Picture id: 2, comment: "Henry McCarty", imageable_id: 1, imageable_type: "Photo", content_type: nil, created_at: "2018-09-20 02:08:02", updated_at: "2018-10-25 13:41:24", name: "Billy_the_Kid_Ferrotype.jpg", designation: nil, blog_id: nil, caption: "Unretouched original ferrotype of Bonney c. 1880", details: "Henry McCarty", copyright_claim: false, source_page: nil, slug: nil>, @messages={:name=>["translation missing: en-US.activerecord.errors.models.picture.attributes.name.blank"]}, @details={:name=>[{:error=>:blank}]}> 

class Picture < ActiveRecord::Base
 belongs_to :imageable, polymorphic: true
 
  def truncated_details
truncated_details=details.truncate(1024, omission:'')
  end

 extend FriendlyId
 friendly_id :truncated_details, use: :slugged  
 
 validates :name, presence: true
 mount_uploader :name, PictureUploader
 has_many :person_pictures
 has_many :people, through: :person_pictures
 has_many :photo_pictures
 has_many :photos, through: :photo_pictures
 attr_accessor  :person_id
 attr_accessor  :picture_id
 def formatted_name
  "#{name.thumb}"
 end

end

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/dee9f8b3-ec57-4943-936c-9d547177d0c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails Wednesday, January 30, 2019



On Wednesday, January 30, 2019 at 5:16:59 PM UTC-5, Colin Law wrote:
On Wed, 30 Jan 2019 at 22:12, Colin Law <cla...@gmail.com> wrote:
>
> On Wed, 30 Jan 2019 at 22:09, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Wednesday, January 30, 2019 at 5:02:17 PM UTC-5, Colin Law wrote:
> >>
> >> On Wed, 30 Jan 2019 at 21:56, fugee ohu <fuge...@gmail.com> wrote:
> >> > ...
> >> > Everything in the unparsed resonse body that I want is between [ and ] I have to gsub it out
> >>
> >>
> >> No you don't.  After you get parsed_obj["results] (which is an array,
> >> that's what the [] mean) then you can get the first product by
> >> parsed_obj["results"][0]["productId"]
> >> It is just an array.  You have met ruby arrays haven't you?
> >>
> >> I am rapidly losing the will to live.
> >>
> >> Colin
> >
> >
> > The response body isn't JSON.parse parsable as is it has to be gsub'd and chomped first before I can run JSON.parse My original gsub wasn't right it wasn't removing the end that follows ]
> > JSON::ParserError: 784: unexpected token at 'myscript.js({"success":true,"code
>
> You previously posted that you had got parsed_obj where
> parsed_obj["results]  was an array.  Go back to that.

To quote your previous message

>puts parsed_obj["results"]  shows the entire results but `puts parsed_obj["results"]["productId"] gets me error no implicit
> conversion of String into Integer

The error is because it is an array, which is perfectly obvious if you
look at the unparsed string. So if you use
parsed_obj["results"][0]
you will get the first element

Colin 

Yes, that returned the actual product id, thanks 

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a00049b2-a7e0-47d1-b645-2be4cea27e25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Wednesday, January 30, 2019 at 5:13:03 PM UTC-5, Colin Law wrote:
On Wed, 30 Jan 2019 at 22:09, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Wednesday, January 30, 2019 at 5:02:17 PM UTC-5, Colin Law wrote:
>>
>> On Wed, 30 Jan 2019 at 21:56, fugee ohu <fuge...@gmail.com> wrote:
>> > ...
>> > Everything in the unparsed resonse body that I want is between [ and ] I have to gsub it out
>>
>>
>> No you don't.  After you get parsed_obj["results] (which is an array,
>> that's what the [] mean) then you can get the first product by
>> parsed_obj["results"][0]["productId"]
>> It is just an array.  You have met ruby arrays haven't you?
>>
>> I am rapidly losing the will to live.
>>
>> Colin
>
>
> The response body isn't JSON.parse parsable as is it has to be gsub'd and chomped first before I can run JSON.parse My original gsub wasn't right it wasn't removing the end that follows ]
> JSON::ParserError: 784: unexpected token at 'myscript.js({"success":true,"code

You previously posted that you had got parsed_obj where
parsed_obj["results]  was an array.  Go back to that.

Colin

 puts parsed_obj["results"]["productId"]
TypeError: no implicit conversion of String into Integer

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/25dbbc61-45ff-4524-87be-9059644121fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Wed, 30 Jan 2019 at 22:12, Colin Law <clanlaw@gmail.com> wrote:
>
> On Wed, 30 Jan 2019 at 22:09, fugee ohu <fugee279@gmail.com> wrote:
> >
> >
> >
> > On Wednesday, January 30, 2019 at 5:02:17 PM UTC-5, Colin Law wrote:
> >>
> >> On Wed, 30 Jan 2019 at 21:56, fugee ohu <fuge...@gmail.com> wrote:
> >> > ...
> >> > Everything in the unparsed resonse body that I want is between [ and ] I have to gsub it out
> >>
> >>
> >> No you don't. After you get parsed_obj["results] (which is an array,
> >> that's what the [] mean) then you can get the first product by
> >> parsed_obj["results"][0]["productId"]
> >> It is just an array. You have met ruby arrays haven't you?
> >>
> >> I am rapidly losing the will to live.
> >>
> >> Colin
> >
> >
> > The response body isn't JSON.parse parsable as is it has to be gsub'd and chomped first before I can run JSON.parse My original gsub wasn't right it wasn't removing the end that follows ]
> > JSON::ParserError: 784: unexpected token at 'myscript.js({"success":true,"code
>
> You previously posted that you had got parsed_obj where
> parsed_obj["results] was an array. Go back to that.

To quote your previous message

>puts parsed_obj["results"] shows the entire results but `puts parsed_obj["results"]["productId"] gets me error no implicit
> conversion of String into Integer

The error is because it is an array, which is perfectly obvious if you
look at the unparsed string. So if you use
parsed_obj["results"][0]
you will get the first element

Colin

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu-tSpdh09GoL98zwgi8vxDY-Ua-YeSVgd5Xxfi8R9NEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Wed, 30 Jan 2019 at 22:09, fugee ohu <fugee279@gmail.com> wrote:
>
>
>
> On Wednesday, January 30, 2019 at 5:02:17 PM UTC-5, Colin Law wrote:
>>
>> On Wed, 30 Jan 2019 at 21:56, fugee ohu <fuge...@gmail.com> wrote:
>> > ...
>> > Everything in the unparsed resonse body that I want is between [ and ] I have to gsub it out
>>
>>
>> No you don't. After you get parsed_obj["results] (which is an array,
>> that's what the [] mean) then you can get the first product by
>> parsed_obj["results"][0]["productId"]
>> It is just an array. You have met ruby arrays haven't you?
>>
>> I am rapidly losing the will to live.
>>
>> Colin
>
>
> The response body isn't JSON.parse parsable as is it has to be gsub'd and chomped first before I can run JSON.parse My original gsub wasn't right it wasn't removing the end that follows ]
> JSON::ParserError: 784: unexpected token at 'myscript.js({"success":true,"code

You previously posted that you had got parsed_obj where
parsed_obj["results] was an array. Go back to that.

Colin

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsNtrhfv8jwR0ip8z6XN%2BiFbD-ZfKj2wpnuZQPru8TNFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Wed, 30 Jan 2019 at 22:05, fugee ohu <fugee279@gmail.com> wrote:
>
> How do I chomp everything at the end of the string starting with ]

You don't. What you have already is fine. Read my previous email.

Colin

>
> --
> 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-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e965ce50-1270-4271-9de4-d3d7062ffd1d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuhqnj5XVG2hMhsAcSAvGYcW8mqke8SoZxJNp03qn0n3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Wednesday, January 30, 2019 at 5:02:17 PM UTC-5, Colin Law wrote:
On Wed, 30 Jan 2019 at 21:56, fugee ohu <fuge...@gmail.com> wrote:
> ...
> Everything in the unparsed resonse body that I want is between [ and ] I have to gsub it out


No you don't.  After you get parsed_obj["results] (which is an array,
that's what the [] mean) then you can get the first product by
parsed_obj["results"][0]["productId"]
It is just an array.  You have met ruby arrays haven't you?

I am rapidly losing the will to live.

Colin

The response body isn't JSON.parse parsable as is it has to be gsub'd and chomped first before I can run JSON.parse My original gsub wasn't right it wasn't removing the end that follows ] 
JSON::ParserError: 784: unexpected token at 'myscript.js({"success":true,"code

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/786b524a-3f59-4576-b51b-7104e680ddd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Wednesday, January 30, 2019 at 12:44:53 PM UTC-5, Colin Law wrote:
On Wed, 30 Jan 2019 at 16:41, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Wednesday, January 30, 2019 at 9:45:03 AM UTC-5, Colin Law wrote:
>>
>> On Wed, 30 Jan 2019 at 13:48, fugee ohu <fuge...@gmail.com> wrote:
>> >
>> >>
>> >> Show us what puts parsed_obj["results"] gives.  If it is long then
>> >> from the start up to where productID occurs.
>> >>
>> >> Colin
>> >
>> >
>> >  {"productId"=>32970292001, "sellerId"=>235696817, "oriMinPrice"=>"US $50.00", "oriMaxPrice"=>"US $50.00", "productTitle"=>"Paid  function", "minPrice"=>"US $50.00", "maxPrice"=>"US $50.00", "orders"=>"1", "productImage"=>"//ae01.alicdn.com/kf/HTB10AX7aPLuK1Rjy0Fhq6xpdFXa5.jpg", "productDetailUrl"=>" ...
>>
>> Are you absolutely sure that is what parsed_obj["results"] is?
>> Frankly I think you are mistaken.
>> Looking at the original source you posted which had
>> "results":[{"productId":32755997022,"...
>> suggests that actually parsed_obj["results"] should be
>> [ {"productId"=>32970292001,...},{...}]
>>
>> Colin
>
>
> Unparsed response looks like this
>  /**/myscript.js({"success":true,"code":0,"results":[{"productId":32962770119, ... ,"itemEvalTotalNum":0}],"finished":false,"page":1,"pageSize":20,"postback":"9954eca0-4297-4d1f-bada-a5c3b131214c","pin":"gps-id=pcDetailLeftTrendProduct&scm=1007.13438.100207.0&scm_id=1007.13438.100207.0&scm-url=1007.13438.100207.0&pvid=778c79a8-9092-483e-92cb-f393856b0565"});
> So if I'm gonna use this approach I have to gsub out everything up to the first [{ after the last }]
> As you can see I was trying another approach as well, need to learn both, substituting the original callback script for myscript.js I can write a function instead of using JSON.parse but I wanna be able to do it both ways

Am I right in saying that parsed_obj is actually an array as I
suggested?  If so then do you not know how to access the elements of
the array?

Colin

How do I chomp everything at the end of the string starting with ] 

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e965ce50-1270-4271-9de4-d3d7062ffd1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Wed, 30 Jan 2019 at 21:56, fugee ohu <fugee279@gmail.com> wrote:
> ...
> Everything in the unparsed resonse body that I want is between [ and ] I have to gsub it out


No you don't. After you get parsed_obj["results] (which is an array,
that's what the [] mean) then you can get the first product by
parsed_obj["results"][0]["productId"]
It is just an array. You have met ruby arrays haven't you?

I am rapidly losing the will to live.

Colin

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu%3DNuwFq2dxaQzk3Tx8A54ndAAEafHjoDzTbPzuTjg-tg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Wednesday, January 30, 2019 at 12:44:53 PM UTC-5, Colin Law wrote:
On Wed, 30 Jan 2019 at 16:41, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Wednesday, January 30, 2019 at 9:45:03 AM UTC-5, Colin Law wrote:
>>
>> On Wed, 30 Jan 2019 at 13:48, fugee ohu <fuge...@gmail.com> wrote:
>> >
>> >>
>> >> Show us what puts parsed_obj["results"] gives.  If it is long then
>> >> from the start up to where productID occurs.
>> >>
>> >> Colin
>> >
>> >
>> >  {"productId"=>32970292001, "sellerId"=>235696817, "oriMinPrice"=>"US $50.00", "oriMaxPrice"=>"US $50.00", "productTitle"=>"Paid  function", "minPrice"=>"US $50.00", "maxPrice"=>"US $50.00", "orders"=>"1", "productImage"=>"//ae01.alicdn.com/kf/HTB10AX7aPLuK1Rjy0Fhq6xpdFXa5.jpg", "productDetailUrl"=>" ...
>>
>> Are you absolutely sure that is what parsed_obj["results"] is?
>> Frankly I think you are mistaken.
>> Looking at the original source you posted which had
>> "results":[{"productId":32755997022,"...
>> suggests that actually parsed_obj["results"] should be
>> [ {"productId"=>32970292001,...},{...}]
>>
>> Colin
>
>
> Unparsed response looks like this
>  /**/myscript.js({"success":true,"code":0,"results":[{"productId":32962770119, ... ,"itemEvalTotalNum":0}],"finished":false,"page":1,"pageSize":20,"postback":"9954eca0-4297-4d1f-bada-a5c3b131214c","pin":"gps-id=pcDetailLeftTrendProduct&scm=1007.13438.100207.0&scm_id=1007.13438.100207.0&scm-url=1007.13438.100207.0&pvid=778c79a8-9092-483e-92cb-f393856b0565"});
> So if I'm gonna use this approach I have to gsub out everything up to the first [{ after the last }]
> As you can see I was trying another approach as well, need to learn both, substituting the original callback script for myscript.js I can write a function instead of using JSON.parse but I wanna be able to do it both ways

Am I right in saying that parsed_obj is actually an array as I
suggested?  If so then do you not know how to access the elements of
the array?

Colin

Everything in the unparsed resonse body that I want is between [ and ] I have to gsub it out

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cdbd3db4-a36c-4c0e-8684-553937a9e74f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Wed, 30 Jan 2019 at 16:41, fugee ohu <fugee279@gmail.com> wrote:
>
>
>
> On Wednesday, January 30, 2019 at 9:45:03 AM UTC-5, Colin Law wrote:
>>
>> On Wed, 30 Jan 2019 at 13:48, fugee ohu <fuge...@gmail.com> wrote:
>> >
>> >>
>> >> Show us what puts parsed_obj["results"] gives. If it is long then
>> >> from the start up to where productID occurs.
>> >>
>> >> Colin
>> >
>> >
>> > {"productId"=>32970292001, "sellerId"=>235696817, "oriMinPrice"=>"US $50.00", "oriMaxPrice"=>"US $50.00", "productTitle"=>"Paid function", "minPrice"=>"US $50.00", "maxPrice"=>"US $50.00", "orders"=>"1", "productImage"=>"//ae01.alicdn.com/kf/HTB10AX7aPLuK1Rjy0Fhq6xpdFXa5.jpg", "productDetailUrl"=>" ...
>>
>> Are you absolutely sure that is what parsed_obj["results"] is?
>> Frankly I think you are mistaken.
>> Looking at the original source you posted which had
>> "results":[{"productId":32755997022,"...
>> suggests that actually parsed_obj["results"] should be
>> [ {"productId"=>32970292001,...},{...}]
>>
>> Colin
>
>
> Unparsed response looks like this
> /**/myscript.js({"success":true,"code":0,"results":[{"productId":32962770119, ... ,"itemEvalTotalNum":0}],"finished":false,"page":1,"pageSize":20,"postback":"9954eca0-4297-4d1f-bada-a5c3b131214c","pin":"gps-id=pcDetailLeftTrendProduct&scm=1007.13438.100207.0&scm_id=1007.13438.100207.0&scm-url=1007.13438.100207.0&pvid=778c79a8-9092-483e-92cb-f393856b0565"});
> So if I'm gonna use this approach I have to gsub out everything up to the first [{ after the last }]
> As you can see I was trying another approach as well, need to learn both, substituting the original callback script for myscript.js I can write a function instead of using JSON.parse but I wanna be able to do it both ways

Am I right in saying that parsed_obj is actually an array as I
suggested? If so then do you not know how to access the elements of
the array?

Colin

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsnsMENQ6i_TsBxFzKNVe9L1Q-d5X2Bz5PEV0mNOHyYdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.