> On Jan 25, 2019, at 9:15 PM, fugee ohu <[email protected]> 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].
> 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/60026bb3-7508-45e5-95b7-558e36734b04%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 [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/39E1B5E7-399B-4762-96A2-0102664AC04B%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to