im using extJS 3.0.0, rails 2.3.11, ruby 1.8.
tables: users -> id, name, is_admin
question -> id, user_id, text
I want to do: If is_admin = 1 - he may see ALL questions. If is_admin = 0 and user_id = 7, he (us开发者_Python百科er number 7) may see only HIS questions (he added 2 for example). How i can do it? In controller i do following trip, but nothing...
my_controller
@questions = Question.find(:all, :conditions => ["user_id = ?", session[:user].id])
in my view (with extJS)
<% if !@questions %>
shows...
<% end %>
You need to check condition for is_admin or not:- In Controller
if session[:user].is_admin == 1
@questions = Question.find(:all)
else
@questions = Question.find(:all, :conditions => ["user_id = ?", session[:user].id])
end
and in views have a loop to display all the questions.
Thanks.....
精彩评论