Sunday, April 25, 2010

Re: [Rails] exiting the function

On Sun, Apr 25, 2010 at 5:20 PM, Conrad Taylor <conradwt@gmail.com> wrote:

> Mohammed, you can write the above as follows:
> @property.destroy if IsAuthorized?(@property.user_id)

Well, you could, *if* IsAuthorized? -- which idiomatically should
be is_authorized? -- returned a boolean value :-)

>>  def IsAuthorized?(id)
>>    if current_user.id!= id
>>      flash[:notice] = 'Not authorized '
>>      redirect_to(properties_url)
>>    end
>>   end

e.g.

def is_authorized?(id)
current_user.id == id
end

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate