how do i access a variable from an initializer file?
i have a file called search.rb in my initializer folder
api_client = IndexTank::Client.new 'http://:[email protected]'
index = api_client.indexes 'idx'
however, in my controller whenever im trying to index a newly created lesson, rails gives me an error of
undefined method `document' for nil:NilClass
my controller is...
def create
index.document(@lesson.id).add({:text => @lesson.content })
end
also is this a bad way of indexing my documents? whenever they're being created? thanks
You might find it useful to look at the Tanker gem by kidpollo - https://github.com/kidpollo/tanker
It's a 3rd party IndexTank gem for rails. You don't actually have to use it - you can keep using the indextank gem if you want. But looking at the source of the Tanker gem may be helpful in figuring out the best way to write your code under rails.