url slugs with special characters

I wanna convert my news stories to use slug urls based on the :headline column instead of id’s but some of the rows contain special characters like double quotes, exclamation points, do I need to gsub those out

An interesting theory, but FriendlyId already does this, quite elaborately. The logic that does the "dumbification" is delegated to ActiveSupport's parameterize method, which takes everything not-ASCII and transliterates it into ASCII, and replaces any run of whitespace with a single dash, and removes punctuation. Next, the slug is checked for duplicates with any existing record, and a UUID is appended if so. It's really quite well done and very settled code. I have been using FriendlyId for 8 years or more without encountering any error that wasn't my own mistake.

In another of your many threads, you mention that you are trying to create a slug out of the article's text, rather than the headline (as the documentation encourages). You may want to try starting from a truncated copy of the article text (or even following the directions) before you assume that FriendlyId is at fault here. I doubt that your article text will fit into the size constraints of a URL segment, particularly if you worry about IE users seeing the thing at all*'

Walter

*The entire URL, including prefix, host, port, and path, must be no more than 1,024 characters ASCII in order to be visited by IE.

I’m trying to parameterize the headline to create the slug I’m getting rollbacks for each record and then " NameError: wrong constant name admin" .rvm/gems/ruby-2.3.3/gems/activesupport-5.0.0/lib/active_support/inflector/methods.rb:268:in `const_get’

So I have to change the length of the varchar field and the length of the index as well?

> > I wanna convert my news stories to use slug urls based on the :headline column instead of id's but some of the rows contain special characters like double quotes, exclamation points, do I need to gsub those out

An interesting theory, but FriendlyId already does this, quite elaborately. The logic that does the "dumbification" is delegated to ActiveSupport's parameterize method, which takes everything not-ASCII and transliterates it into ASCII, and replaces any run of whitespace with a single dash, and removes punctuation. Next, the slug is checked for duplicates with any existing record, and a UUID is appended if so. It's really quite well done and very settled code. I have been using FriendlyId for 8 years or more without encountering any error that wasn't my own mistake.

In another of your many threads, you mention that you are trying to create a slug out of the article's text, rather than the headline (as the documentation encourages). You may want to try starting from a truncated copy of the article text (or even following the directions) before you assume that FriendlyId is at fault here. I doubt that your article text will fit into the size constraints of a URL segment, particularly if you worry about IE users seeing the thing at all*'

Walter

*The entire URL, including prefix, host, port, and path, must be no more than 1,024 characters ASCII in order to be visited by IE.

So I have to change the length of the varchar field and the length of the index as well?

I don't know what your schema looks like right now. Here's how I have always used FriendlyID:

1. I have a `title` column, normal string, 255 characters limit. The client or user can enter whatever she wants up to that limit. 2. I use the FriendlyID migration generator to create the slug column on my model. 3. I configure FriendlyID according to the instructions (extend, then friendly_id :title, use: :slugged in the model). 4. Profit.

There's really nothing else needed except changing find to friendly.find in the controller.

I don't give the client/user the ability to create a too-long slug, by starting from a source text that is short enough.

If you wanted to start from the article text (say, a true text field of thousands of characters), I would start by trimming that text down to the first couple hundred characters. And then, because slugs must be unique, I would imagine you would have quite a few natural collisions, and might end up with a fair amount of disambiguated slugs that end in UUID-shaped garbage strings.

I believe that FriendlyId has the ability to call methods (rather than being bound to just the actual database columns) when calculating the slug, so you could start from `article_body` (a text column, tens of thousands of characters or a clob) and then limit that with truncate or another string-splitting method, like this:

(in your model)

friendly_id :article_preview, use: :slugged

def article_preview   # cut off at 200 characters, without an ellipsis   article_text.truncate(200, '') end

Does that make sense?

Walter

Yes I forgot that my :headline column is actually text so this would be necessary Also I don’t see reason to use friendly_id for anything but the show action, why try to find records by slug for edits, updates and deletes?

> > > > > > > > I wanna convert my news stories to use slug urls based on the :headline column instead of id's but some of the rows contain special characters like double quotes, exclamation points, do I need to gsub those out > > An interesting theory, but FriendlyId already does this, quite elaborately. The logic that does the "dumbification" is delegated to ActiveSupport's parameterize method, which takes everything not-ASCII and transliterates it into ASCII, and replaces any run of whitespace with a single dash, and removes punctuation. Next, the slug is checked for duplicates with any existing record, and a UUID is appended if so. It's really quite well done and very settled code. I have been using FriendlyId for 8 years or more without encountering any error that wasn't my own mistake. > > In another of your many threads, you mention that you are trying to create a slug out of the article's text, rather than the headline (as the documentation encourages). You may want to try starting from a truncated copy of the article text (or even following the directions) before you assume that FriendlyId is at fault here. I doubt that your article text will fit into the size constraints of a URL segment, particularly if you worry about IE users seeing the thing at all*' > > Walter > > *The entire URL, including prefix, host, port, and path, must be no more than 1,024 characters ASCII in order to be visited by IE. > > > So I have to change the length of the varchar field and the length of the index as well?

I don't know what your schema looks like right now. Here's how I have always used FriendlyID:

1. I have a `title` column, normal string, 255 characters limit. The client or user can enter whatever she wants up to that limit. 2. I use the FriendlyID migration generator to create the slug column on my model. 3. I configure FriendlyID according to the instructions (extend, then friendly_id :title, use: :slugged in the model). 4. Profit.

There's really nothing else needed except changing find to friendly.find in the controller.

I don't give the client/user the ability to create a too-long slug, by starting from a source text that is short enough.

If you wanted to start from the article text (say, a true text field of thousands of characters), I would start by trimming that text down to the first couple hundred characters. And then, because slugs must be unique, I would imagine you would have quite a few natural collisions, and might end up with a fair amount of disambiguated slugs that end in UUID-shaped garbage strings.

I believe that FriendlyId has the ability to call methods (rather than being bound to just the actual database columns) when calculating the slug, so you could start from `article_body` (a text column, tens of thousands of characters or a clob) and then limit that with truncate or another string-splitting method, like this:

(in your model)

friendly_id :article_preview, use: :slugged

def article_preview   # cut off at 200 characters, without an ellipsis   article_text.truncate(200, '') end

Does that make sense?

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/0d80957a-d522-4f30-9aeb-a355ea132b0b%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout.

Yes I forgot that my :headline column is actually text so this would be necessary Also I don't see reason to use friendly_id for anything but the show action, why try to find records by slug for edits, updates and deletes?

No, there's no actual reason you have to do this for all routes. You can mix the two (Article.find and Article.friendly.find) within the same controller.

Another thing you may have missed in the documentation is that friendly.find will also find the actual record by its ID, too. So there's no harm in passing the ID in most of the routes and the slug in one route, one method will find either way. I suppose it may be slower that way, but only just a little. This happens here:

Walter

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

I’m working in the rails console

In Gemfile.lock friendly_id (5.2.5) is listed under GEM and friendly_id (~> 5.2.4) is listed under DEPENDENCIES

Also at system prompt gem list shows 5.1.0 is installed as well as a left over dependency for spree_core 3.2.8 which I’m not using anymore

$ gem list friendly_id

*** LOCAL GEMS ***

friendly_id (5.2.5, 5.1.0)

ActiveRecord::RecordInvalid: translation missing: en-US.activerecord.errors.messages.record_invalid

from (irb):1

Nothing under the GIT section in Gemfile.lock related to this gem

I think you missed the point of this. Use git log Gemfile.lock to see the various save points of this file over time, and see if the line that includes friendly_id(your.version.number) has ever changed in that time.

Walter

> > > > > > > > > > > > > > > > > > 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

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

> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 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