On 6 July 2015 at 14:18, Padmahas Bn <[email protected]> wrote: > Based on railstutorials.org, I've written my method to check whether it is > admin or not inside sessions_helper.rb. Now in model I've to insert data to > temporary table lets assume "user_temp_table", if it is normal user that has > logged in. Later those entries will be approved by admin. If it is admin > himself logged in I want to insert data to permanent table lets assume > "admin_table". > > Now where is the best place to call admin checking method which I have > written inside sessions_helper.rb. > I have two possibilities. > > 1. Set a flag to 1 or 0 inside controller and access that flag variable from > model if it is admin or user respectively. > Problem: But I found some blogs and stackoverflow posts stating that > controller is just a bridge between view and model. And variables inside > controller should not be accessed from model. Addition to that I don't know > how to access controller variable from model. If this is the method please > tell me how? > > 2. include SessionHelper inside model and call the method. > > But posts I found related to both of these solutions are very old. So in > rails 4 which is the valid and good way to carry out this task? Or is there > is any other new way?
Not sure what your helper method is doing, but I think I would have a method in the user model so you can just say if current_user.admin? or something similar. Colin > > Thank you. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/21019c25-87c5-4eec-990d-789a724d710a%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvjd%2BU3U7c23j-7%2BqUaGjBjps_OmzqRcQw%2BX%3DrqCz0WvA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

