Ruby On Rails Database - ruby-on-rails

Whenever I run the command rvmsudo rake db:migrate (I need to use rvmsudo because I'm using rvm), the sqlite3 files generated are owned by root.
ls -l db/*.sqlite3
Because of this, I keep on getting a SQLite3 Read Only Error whenever I try to do anything to the database, and I have to manually enter the command:
sudo chown -R myusername db/*.sqlite3
rvmsudo rake db:migrate never did this before, and I am wondering why it is happening now.

Did you install RVM as root, and if so, is there a reason it wasn't installed as your normal (less-privileged) user? I use RVM daily, on a number of machines, and haven't had to install RVM as root.

Related

When executing "bundle exec rails runner", how can I specify the application's directory?

When I execute this command:
/usr/local/bin/bundle exec rails runner -e production "load 'job_alerta_validacao.rb'"
It returns:
Could not locate Gemfile
How can I set where the application is directly in the command without needing to create a script with the "cd" command?
The most common way to use bundler is to cd to the directory containing the Gemfile. This is also the most robust way, since some other gems will probably assume that the working directory is the root of the Rails project.
If you just don't want to change your current shell's working directory, cd in a subshell:
(cd /some/directory; /usr/local/bin/bundle exec rails runner -e production "load 'job_alerta_validacao.rb'")
If you really want to execute something through bundler with a working directory other than the directory with the Gemfile, tell bundler where to find the Gemfile with the BUNDLE_GEMFILE environment variable:
BUNDLE_GEMFILE=/some/directory/Gemfile /usr/local/bin/bundle exec rails runner -e production "load 'job_alerta_validacao.rb'"

bundle exec rake db:migrate says Run `bundle install`

bundle install
This works perfectly fine. But when I do
bundle exec rake db:migrate
It says
Could not find byebug-6.0.2 in any of the sources
Run `bundle install` to install missing gems.
From comments, I saw that you use 2 different types of commands, 1 with sudo and 1 without.
Problem is: sudo is another user (root user), so what you install by sudo may not be applied for other users and vice versa.
The solution I could think of is to use all sudo commands, since your current user seems not to have access to PG.
sudo bundle install
sudo bundle exec rake db:migrate
I just troubleshat this same problem. I finally tried removing byebug and was offered a choice of byebug_6.0.2 or byebug_8.1.0. Removing the earlier version didn’t do it so I removed the other as well. I then reinstalled using
gem install byebug
That gave me another failed migrate, this time blaming debug_inspector. I ran
gem install debug_inspector
After that I was able to run rake db:migrate as expected.

Sudo Access to Rails gem installed from Github

I am required to run the following Ubuntu bash script as "sudo" (FYI, this is because I am running it through Upstart):
cd /u/apps/MyRailsApp/current && /usr/bin/env RAILS_ENV=production script/delayed_job restart >> /var/log/upstart/delayed_job.log
However, when I run it as "sudo", I get the following error:
/var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/source/git.rb:188:in rescue in load_spec_files': git#github.com:MyRemoteRepo/my_gem.git (at 1.0.1) is not yet checked out. Runbundle install` first. (Bundler::GitError)
It's not recommended to run "bundle install" as Sudo. When I run "bundle install" as a non-admin user, it is working and all the gems are recognized. How do I get the root user to recognize the gem?
The gem is in /home/ubuntu/.bundler/ruby/1.9.1/. My other gems are in /var/lib/gems/1.9.1/gems/
Thanks so much for your help.
Try adding "source /home/[username]/.bashrc" where [username] is non-admin user that can run the script successfully.

Sphinx Index doesnot work when running in development

I have installed sphinx and have done all necessary changes followed this steps
wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
tar -xzf sphinx-0.9.9.tar.gz
After that, we should compile Sphinx from the source:
cd sphinx-0.9.9-rc2/
./configure
sudo make
sudo make install
In Rails 3, open Gemfile in the root directory and add the line below:
gem 'thinking-sphinx', :git => 'http://github.com/freelancing-god/thinking-sph
And run the following command:
bundle install
Thinking Sphinx gem adds a few rake tasks to your application. The most important ones:
rake thinking_sphinx:index – Create the index
rake thinking_sphinx:reindex – Reindex Sphinx without regenerating the configuration file
rake thinking_sphinx:start – Start up Sphinx's daemon
rake thinking_sphinx:stop – Shut down the daemon
but getting error FATAL: no indexes found in config file '/home/gvo/dcms/config/development.sphinx.conf'
but when i run same with RAILS_ENV= production it works fine. Any suggestion or help would be really great.
Yeah, those names are confusing. You need to make sure the ThinkingSphinx configuration in app/config/sphinx.yml (paths, what to index) is available to the TS gem for your environment. TS uses this config to generate the configuration used by the underlying Sphinx server. You may have to create needed directories for the indexer to be able to write index files, logs, and a few other things. It's likely that the config for development is different than production.

Deploying Chiliproject to Dreamhost

Having some issues deploying this. I've tried to deploy it twice now. Here's what I've done so far....
Installed the gems and versions required on the install page:
gem install -v=2.3.5 rails
gem install -v=1.0.1 rack
gem install -v=0.8.7 rake
gem install -v=0.4.2 i18n
Downloaded the package:
git clone git://github.com/chiliproject/chiliproject.git
cd chiliproject
git checkout stable
Had to find and set bundle since it wasn't in my path:
BUNDLE="/usr/lib/ruby/gems/1.8/bin/bundle"
Put my database info into database.yml:
And then started the bundle stuff:
$BUNDLE install --without=postgres rmagick
$BUNDLE exec rake generate_session_store
The last command got the error:
rake aborted!
can't activate rails (= 2.3.5, runtime), already activated rails-2.3.12. Make sure all dependencies are added to Gemfile.
So I changed 2.3.12 to 2.3.5 in the Gemfile and carried on:
RAIL_ENV=production $BUNDLE exec rake db:migrate
Then I got an error on this command too:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
undefined method `autoload_paths' for #<Rails::Configuration:0x68a68dbb82c0>
/home/USERNAME/DOMAIN/public/config/environment.rb:44
I tried commenting out line 44 there, but then it threw another error undefined methodconvert_to_without_fallback_on_iso_8859_1' for class Class' so I didn't want to play around with it further. Note this only happened the second time I tried to deploy it. The first time I tried db:migrate succeeded (and I checked there was not data already in the DB).
*So for the second try I am stuck here :-( *
But this is what happened the first time after db:migrate succeded....
RAILS_ENV=production $BUNDLE exec rake redmine:load_default_data
With the last command however it failed saying permission denied for mysql 'user'#'173.236.128.0/255.255.128.0' and I was like WTF is it trying to connect to a network as if it were a host?
So I moved on, copied my configuration file and environment files in. Changed/added these lines:
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5'# unless defined? RAILS_GEM_VERSION
if ENV['RAILS_ENV'] == 'production' # don't bother on dev
ENV['GEM_PATH'] = '/home/USERNAME/.gems' + ':/usr/lib/ruby/gems/1.8'
end
Then made this stuff writable and restarted Passenger:
chmod -R 777 files log tmp public/plugin_assets/
touch tmp/restart.txt
Sorry for the wall of text, is anybody able to shine some light on something I've done wrong?
Thanks in advance.
EDIT: So this is all wrong, here's how I got it working
rm ~/.gem*
gem install bundler
PATH=$PATH:/usr/lib/ruby/gems/1.8/bin
cd ~
git clone git://github.com/chiliproject/chiliproject.git
cd chiliproject
git checkout stable
cp * ../example.com/ -R
cd ../example.com
# Make sure database is working
bundle install --without postgres rmagick test
bundle exec rake generate_session_store
RAILS_ENV=production bundle exec rake db:migrate
# No output is no good, check database.yml
RAILS_ENV=production bundle exec rake redmine:load_default_data
Or see this: https://gist.github.com/1127306
The current ChiliProject stable releases (2.x) require the use of bundler. Thus the answer by Slotos is incorrect here. gen install doesn't work anymore, we NEED bundler.
Also, we require Rails 2.3.12 now. You won't get any working results if you arbitrarily edit files. On certain platforms, you need to adapt the Gemfile (e.g. when using Ruby 1.8.6 or for certain versions of ImageMagick). For the currently suggested setup using Ruby 1.8.7 or REE, you don't need to adapt anything though.
For installing the dependencies of the currently stable ChiliProject 2.x releases, you basically need to do the following:
At first you need to make sure that the directory where gem binaries re installed to is in your $PATH. This can be temporarily be achieved by running this (in your case)
export PATH=/usr/lib/ruby/gems/1.8/bin:$PATH
Then you need to install the bundler gem and instruct it to install all dependencies
gem install bundler
bundle install --without rmagick postgres test # in your case
What is really strange in your case is that rake seems to try to enable Rails 2.3.5. It should not do that (and doesn't unless you have changed certain files). I strongly recommend to start with a new clean source tree and don't change any arbitrary files.
Don't mix up gem install commands with bundler package management. You will get unexpected results from doing so.
If you really want to use bundler - add all the gems you want into a Gemfile.
Otherwise just omit it.
Quick search for "bundler chiliproject" lead me to chiliproject-gemfile. Apparently it have been merged into unstable already.

Resources