This project is archived and is in readonly mode.
add first_bang to AR
Reported by Josh Susser | March 24th, 2011 @ 05:03 AM | in 3.1
Before scopes, controller methods did this:
@user = User.find(params[:id])
Now with scopes you can do
@user = User.where(:id => params[:id]).first
However that doesn't raise an exception when the record is not found. With this patch, you can do this:
@user = User.where(:id => params[:id]).first!
And that raises the RecordNotFound exception, as you'd expect.
Comments and changes to this ticket
-
Andrew White March 24th, 2011 @ 11:17 AM
- State changed from new to open
- Milestone set to 3.1
- Assigned user changed from Aaron Patterson to Andrew White
- Importance changed from to Low
Josh, can you add last! as well to the patch and I'll apply it
-
Josh Susser March 24th, 2011 @ 04:45 PM
By the way, the simplistic example given in the original ticket above isn't the motivating use case. That would be using an association or scope to find a record.
def show @latest_update = current_user.updates.recent.first! end
-
Aaron Patterson March 24th, 2011 @ 04:55 PM
- State changed from open to committed
Applied and pushed. Thanks.
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>