How do I write this method in RoR?
if item is nil or item.user!='my_value' redirect_to "/"
Want to call it like so:
@item = Item.find(params[:id])
method_described_earlier(@item)
Or other way.
Want to see how rails pro would do it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should use a before_filter, which will run before any set of controller actions you indicate. For example:
The method
require_special_itemwill always run beforemyactionand any other actions you indicate, redirecting the user if the found item doesn’t meet your requirements.