friendly_id Model.find_each(&:save)

Model.find_each(&:save) This command doesn’t work for me, each commit causes ROLLBACK and at the end an error from active storage " invalid constant name ‘admin’ " what does the &:save actually mean?

Model.find_each(&:save) This command doesn't work for me, each commit causes ROLLBACK and at the end an error from active storage " invalid constant name 'admin' " what does the &:save actually mean?

Symbol to Proc is what this is called. It's a language feature in Ruby that lets you apply a method to a number of objects within an enumerable structure. To illustrate, here's a trivial example:

%w[foo bar baz] &:upcase --> ['FOO', 'BAR', 'BAZ']

Array goes in, each element of the array has upcase called against it, and a new array is returned containing the upper-case results. If you called &:upcase! instead, the same array would be returned, with the values within it mutated in place.

It's similar to calling map() and passing a block.

Getting back to your error message, do you, by any chance, have a column in your model named (exactly) `type`? If so, and you have a single-table-inheritance setup or a polymorphic join, and you try to add a lower-case string to that column, that could explain the error. The values that go into type should be contantized (initial cap). I'm not sure if the values are checked against the other model names in the application, but if they are, then you would also have to add a constant-shaped value that actually matched one of the other models in your application.

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, '')

end