I'm making a Ruby on Rails gem and need access to variables like cookie or the query parameters. How do I get this from inside a gem?
module MyModule
def self.my_method
# need access to cookies, query params, etc
end
end
So that from a controller or view, I can call
MyModule.my_method
and it'll have the access it needs.
You need to pass in what you want. Whether you want to pass in each individually or pass in the request object and pull out what you want depends on how/where you'll use your gem. I would lean towards passing in each individually in a well defined format so there aren't any surprises b/n rails servers and what the request object looks like.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.