This project is archived and is in readonly mode.
update_attribute is annoying, what about a bang method?
Reported by Juan Maiz (aka João Milho or John Corn) | March 23rd, 2011 @ 02:17 PM
I'm tired of writing update_attribute. Hope it's not just me. I propose having a bang method in attributes:
@foo = Foo.find(10) @foo.bar! 'baz' // will update bar to baz
Comments and changes to this ticket
-
Rafael Souza March 23rd, 2011 @ 08:35 PM
+1, sounds cool for me
update_attribute sometimes confuses me, I often try to pass a hash for it, mainly when I write some update_attributeS before :)
-
Juan Maiz (aka João Milho or John Corn) March 23rd, 2011 @ 08:36 PM
The implementation also seemed very natural.
Read:
@foo.barWrite:
@foo.bar=Query:
@foo.bar?... ergo Update: @foo.bar!
... looks like the project was asking for an Update module :D
-
Corey Ward March 24th, 2011 @ 05:39 PM
-1
Dropping
=
is actually counter-intuitive and not very Ruby-like. It's even less Rails-like.It's pretty easy to use:
@foo.bar = 'baz' and @foo.save
Or if you prefer not to have an
and
(and I can't blame you):@foo.set(:bar, 'baz')
Seems pretty straightforward and much shorter, plus it's just an alias for
update_attribute
. -
Andrew White March 24th, 2011 @ 07:45 PM
- State changed from new to wontfix
- Importance changed from to Low
The consensus seems to be that it seems more like a shortcut for updates_attributes!, e.g:
def foo!(value) update_attributes!(:foo => value) end
Thanks for the suggestion though.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>