Ruby on Rails
Monday, July 6, 2015
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?
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment