Ruby on Rails Monday, July 6, 2015

Can you share the content of session_help.rb?
In your Users table, do you set a flag to indicate whether or not the user is admin?
The Controller informs and interacts with your Model.
When the user logs in,  you have a controller method that manages login.  You try to find the user by username, password, email or some combination...

def login






On Monday, July 6, 2015 at 9:18:43 AM UTC-4, Padmahas Bn 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?

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/d06cf12f-02f7-4288-84c2-e2da88cf0012%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment