passing geocoder information to the views?
I am using geocoder gem to get location information about the user. The issue I am facing is how to pass this information 开发者_如何学运维to the views and the application as a variable?
I do not want to query the api each time a new page is loaded but also want to retain the location information that views and controllers and use it.
To pass a gobal variable from a controller to a view you need to use @
in front of your variables (e.g. @geodata
being your object).
To save the information you should either add some field location
to your User
model or create a new Geowhatever
model and assign it to each user (and maybe to other models via polymorphism).
This way you can do @user.location
or @user.geowhatever.location
in your views.
The only caveat when doing caching is to keep the cache up to date. Here an observer UserObserver
can do the task.
精彩评论