On Saturday, January 26, 2019 at 12:40:12 PM UTC-5, Walter Lee Davis wrote:
>
>
> > On Jan 25, 2019, at 9:15 PM, fugee ohu <[email protected] <javascript:>>
> wrote:
> >
> > 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
>
>
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected] <javascript:>.
> > To post to this group, send email to [email protected]
> <javascript:>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/60026bb3-7508-45e5-95b7-558e36734b04%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, '')
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/016fd2b1-9b48-415d-9fd4-92974951a9fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.