Sunday 15 April 2012

ruby on rails - How to access session information from within model? -


Put it in a very tasteful way:

..] are incorrect if you want to use sessions, parameters, cookies etc. in your model.

However, I think I have a valid case for this - and if not, then please give me a different perspective

I am using KeenIO api to publish a program when a user registers on the website is not logged, but registers a new user

  # control code: @ user = user.find_or_create_for_gitube_outh (request.env ["omniauth.auth"], current_useor) # Model method: user = User.find_by (Email: Auth_hash [' Info '] [' email ']) if user.nil? # User is brand new, bla bla bla eager (publish: account_registration_au, {user_session: {session_id: session.id}} end  

I have information about session from within my model How can I get it? I am trying to create a deep mist and I need a session ID to track the user through my funnel steps.

I like to describe the MVC pattern with the following picture:

Therefore, There is no doubt that the most important part of any application is data - without any data, the web application is just a static website so your data makes your website unique and this will be the first reason why the customer can

Now imagine some strange animals living on your distant planet - small living arrangements living there: heavy articles slowly The rays are running, along with their ongoing comments under the feet, the authors have fed upvots etc. This is the domain of your application - this is the true model and you are here as God.

Now you are building your application in that world. You have to make a small village in it, it will have its own post office (server), and small buildings are called controllers. When a new request arrives, your post office reads its address and sends it to the right controller. Now the people of the controller will read the message and decide that they need some data to take action on it - the hunting team is called and They go to the forest to catch him. (Actually they make a picture of it, unless you do not pessimistic locking, long story). This data is processed and goes to the controlling secretary, which pastes this processed data for a ready template (it is not exactly what it is - it's not his job). It will then return to a post office as if sent back as a response.

Important things to pay attention to here:

  1. Your controller is the heart of your application The vast field of your model
  2. The model does not care about your application
  3. You do not want some goats to be surprised about your shiny office, do you?

Passing application-specific data is fine for the model, if you want to shape the current ecosystem, however, access to applications controls like sessions or cookies is extremely risky. Passing the example of the controller for a model is to send the director of the zoo to feed the wild tigers.

In addition, feeding models with additional application data will make them application dependent and they will not survive when you open the console for example


No comments:

Post a Comment