Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRichard English
14,012 PointsLimiting access to edit statuses in Rails project
It's possible i missed this in one of the videos, but here goes.
How do I limit access to the edit status page, to only the owner of the status. Can I use a before filter that checks if the user is the right one? What would that look like?
Thanks
Richard
2 Answers
Uriel Hernández
3,681 PointsI'm not that sure, but it could be something like:
before_filter :validate_user, :only => :edit
def validate_user s = Status.find(params[:id]) redirect_to "/" unless s.user.id == current_user.id end
I'm not sure if that fits for what you need, but if not, it must require just some adjustments.
Sorry about my english.
Richard English
14,012 PointsThanks Uriel,
It worked!
Richard