开发者

passing geocoder information to the views?

开发者 https://www.devze.com 2023-03-23 18:37 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号