Skip to content

Instantly share code, notes, and snippets.

@Gregg
Created January 14, 2011 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gregg/780244 to your computer and use it in GitHub Desktop.
Save Gregg/780244 to your computer and use it in GitHub Desktop.
Use scope access
# Even when you create objects they should be properly scoped... Remember this example?
t = Tweet.new
t.status = "RT #{@tweet.user.name}: #{@tweet.status}"
t.original_tweet = @tweet
t.user = current_user
t.save
# A simplified version of this, properly scoped might look like this:
current_user.tweets.create(
:status => "RT #{@tweet.user.name}: #{@tweet.status}",
:original_tweet => @tweet
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment