elias_t
elias_t

Reputation: 83

Devise public user page only if user is pro

I have a devise user model with pro boolean column.I want to build a public page for each of them but only if user is pro.How can i approach it?

Upvotes: 0

Views: 313

Answers (2)

Grzegorz Łuszczek
Grzegorz Łuszczek

Reputation: 548

If you build public page, you propably use User.find(params[:id]) for get user information. Change that to User.where(:id => params[:id], :pro => true).first. Then just check that user exist or we had only nil.

Upvotes: 0

creativetechnologist
creativetechnologist

Reputation: 1462

That's quite straightforward.

First you need to change your user.rb model and add the new column to the attr_accessible, so it looks something like ...

attr_accessible :email, :password, :password_confirmation, :remember_me, :pro

Now you can use the following statement to test if a user is a 'pro' ...

if current_user.pro
    #some page display code
end

You can also use a before_filter in the controller which displays your public page, you'll need to read the devise documentation a bit more and perhaps check out this post

Upvotes: 1

Related Questions