Controller:
@events = Event.all
@events.each { |e| e.user_subscribed = "someuser" }
@events.each { |e| puts "error" + e.user_subscribed }
I have attr_accessor :user_subscribed. but the error is can't convert nil into String as e.user_subscribed evaluates to nil.
I’m using mongoid on the backend.
edit: this works, but it just copies the whole array.
@events = @events.map do |e|
e.user_subscribed = "faaa"
e
end
If you’re not saving the @events to the database, user_subscribed won’t persist, unless you keep it in memory: