When the user is logged in, only the user who create the record can destroy his own record.
What should I add to the code below??
def destroy
@topic = Topic.find(params[:id])
@topic.destroy
flash[:notice] = "topic deleted!"
end
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.
What you are looking for is not really devise but a authorization solution like CanCan.
Devise can only authenticate users and verify that they are logged in and active. What you need is a way to determine if the user has the right to delete this topic or not.
You can of course roll your own like this:
(The code assumes you have a
belongs_to :creator, :class_name => :userassociation set up in your Topic.. But you get the idea).But using something like CanCan will make your life a whole lot easier and would reduce the code to something like this:
With your ability file (See defining abilities) set up like this: