Reindex only a single Model from the command line in SearchKick - ruby-on-rails

I am stuck trying to reindex a single model in SearchKick.
If I run the following command:
rails Profile.reindex
I get the following error:
Profile.reindex: command not found
I am able to run the command
rails searchkick:reindex:all
but that takes over an hour because of the size of my other models.
Any help would be appreciated.
Thanks,
Gerard

You can re-index just the Profile class using
rails searchkick:reindex CLASS=Profile
If you just run
rails searchkick:reindex
It will provide the USAGE explanation
Example buried in the Docs
Explanation in the Source Code: Searchkick rake tasks

If you are in the rails console, Profile.reindex should work fine, provided you have set up searchkick in the model.

Related

Trying to Execute Ruby Code for the first time.

Project:
https://github.com/jmopr/job-hunter
Background:
Took only 2 intro course on Java 7 years ago.
So I was browsing GitHub and ran across this nifty project that deals with scraping & applying for jobs on indeed.com.
The question is, how do you run it? Here is what I tried to do:
Tried to execute applier.ru I figured I was doing something wrong after getting:
/home/shap/Desktop/job-hunter-master/applier.rb:19:in initialize': uninitialized constant JobApplier::Job (NameError)
from /home/shap/Desktop/job-hunter-master/applier.rb:169:innew'
from /home/shap/Desktop/job-hunter-master/applier.rb:169:in `'
Something was missing, so looking around I found the bin folder and tried executing /bin/setup.ru but i ran into this error:
== Preparing database ==
/var/lib/gems/2.3.0/gems/railties-4.2.5.1/lib/rails/application/configuration.rb:110:in database_configuration': Cannot loadRails.application.database_configuration`:
Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
Are we supposed to generate our own database file? how would we do that?
Any help or even a push in the right path is deeply appreciated.
You are supposed to generate your own database configuration. It should be stored at config/database.yml. It's a file that specify where's your db server, what's the name of the database and what should be the credentials to access it. Google "rails database.yml example".
Once you have that, creating your actual database is as easy as running these commands
rake db:create
rake db:migrate
There may be many-many other different obstacles on your journey of making this application run. Things that are obvious to rails devs, but arcane to total strangers. I suggest finding and completing a ruby on rails tutorial.
This is ruby on rails project,
after checkout you need install all required dependencies, with command
bundle exec install
Run project you can with command
./bin/rails server
If project is started successful, you can access it with browser using address http://localhost:3000
more about rails you can find there http://guides.rubyonrails.org/getting_started.html
http://guides.rubyonrails.org/getting_started.html

searchkick Index missing in ruby application

Im trying to use Searchkick in my application. However, I get
Searchkick::MissingIndexError
Index missing - run Product.reindex
def search
if params[:search].present?
#product = Product.search(params[:search])
else
#product = Product.all
end
I run Produc.reindex but it didn't solve the issue. I also tried following : rake searchkick:reindex:all and I receive the Reindex complete message which is followed by rake db:migrate; however,I come up with the same missing index error when I submit the search query.
any advice and suggestions will be greatly appreciated
Using Rails 4.1.8 and Elastic Search 2.4.6, I was facing this same problem in the production environment, and when I tried to access the action URL of the autocomplete action I was receiving the same Index missing - run Product.reindex error message. However, in development environment Elastic Search was working without problems.
Usually, I use the following command to reindex my class:
rake searchkick:reindex CLASS=Product
So, following #Aref Aslani comment, I tried this command:
RAILS_ENV=production rake searchkick:reindex CLASS=Product
And it worked!
You can simply launch your Rails Console and then type
Product.reindex
I had a similar error in my application and so I just decided to understand the error message and then tried it on the console as if I am testing a feature and it worked perfectly.
I got same issue in the rails development environment, Rails 5.2.3, ruby 2.4.0, so
resolved it by using the following command:
rails searchkick:reindex CLASS=<ClassName>
like
rails searchkick:reindex CLASS=ThreeDGarment

Cannot deploy with Passenger

I'm trying to deploy my first app with rails. I'm unable to deploy it, and I'm unhappy because the framework itself allowed me to develop really quickly the application, but I've only two days to make the deployment work :-(
I've installed and configured passenger following a tutorial (i'm using RVM).
When I access the page I have the following error page: traceback here (posted on pastebin to keep this post clear).
What is wrong?
i just uploaded the whole project on the production server, ran bundle install, rake db:create rake db:migrate and rake db:seed. Am I missing some step?
Why it doesn't run?
Developed using Rails 3.2.3 with Ruby 1.9.3.
Please help me to get it running.
Thanks,
Alex.
I have very little information about your problem but I have and idea what is going on. Check your belongs_to association in your event model if there is a class parameter replace it with class_name.

ActiveRecord::StatementInvalid after laptop re-image

I have run my first scaffold command to see if all is well, after the book purchase agile web development with rails.
rails generate scaffold product name:string
Upon loading WEBrick, I see the following error.
ActiveRecord::StatementInvalid in ProductsController#index
Debugging steps carried out on my own:
db migration looks well formed (although who am I to review?)
loaded sqlite3 shell and cannot find the products table
gem file contains a gem 'sqlite3' line
Really new to Rails and have tried to solve this problem myself and struggling to connect the dots.
Any advice or support would be appreciated.
Run rake db:migrate after generating the scaffold.

Rails script error

i wrote a script to fill a database using values from an excel page. In the script I'm getting the error
uninitialized constant Profile (NameError)
Profile is the name of a model i have. Rails looks it is not recognizing my model in the script. How can fix this.
It looks like Rails doesn't get properly initialized.
Can you post the script, and explain how you run / start it?
Which version of Rails do you use?
If you have a rails application and you want to run a task as a script, there are two ways to do it:
1) via script runner
2) via rake
If you use rake, you have to tell it to initialize your Rails application properly.
The rake tasks need to be under ./lib/tasks
Check out these Posts, which explain how to do it:
I have a Rails task: should I use script/runner or rake?
script/runner in rails 3
http://guides.rubyonrails.org/active_record_querying.html

Resources