Syntax error on rake db:schema:dump - ruby-on-rails

I try to connect mysql with ruby, I follow this video
https://www.youtube.com/watch?v=GY7Ps8fqGdc
but on 23:30 in video, I got error with rake db:schema:dump,
I have no idea, this is my error:
irb(main):016:0> rake db:schema:dump
SyntaxError: (irb):16: syntax error, unexpected tLABEL
rake db:schema:dump
^
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

rake is a command-line tool. It is not supposed to be executed inside irb or the Rails console.
Try doing that from the command-line.
irb is for evaluating Ruby code only, which is a different thing than the command-line tools like rails and rake even if they are written in Ruby.

At the outset, get out of irb console.
rake is a build program, similar to make. Just go to your project directory on terminal and run your rake commands like:
~/apps/myproject$ rake db:schema:dump

Related

Active storage installation does not work

I have a Rails application for which I wanna install the gem active storage so that I can save photos on my application and interact with them. Despite that, I input in the console
rails active_storage: install
and I get the following error:
rails aborted!
LoadError: cannot load such file -- active_storage
C:/Users/andri/Desktop/hoagieShop/hoagieShop/config/application.rb:4:in `require'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/config/application.rb:4:in `<top (required)>'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/Rakefile:4:in `require_relative'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/Rakefile:4:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
Does anyone understand why? I tried the solution provided here: rails active_storage:install IS NOT WORKING but it did not work.
in terminal/app folder
reset db
rake db:reset
migrate db
rake db:migrate
update the gem file
bundle install

LoadError: cannot load such file --rails on 'rake db:setup'

I'm having an issue trying to switch the database in my rails app from the out of box sqlite3 to using postgres.
I've run 'gem install pg' and switched the database.yml file to new settings. Also, I've run 'bundle install' in the directory.
Now, when I run 'rake db:setup', I'm receiving this error:
$ rake db:setup
rake aborted!
LoadError: cannot load such file -- rails
/Users/aaa/Documents/Projects/sample_app/config/application.rb:3:in `require'
/Users/aaa/Documents/Projects/sample_app/config/application.rb:3:in `<top (required)>'
/Users/aaa/Documents/Projects/sample_app/Rakefile:4:in `<top (required)>'
/Users/aaa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/Users/aaa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
Any thoughts? Thank you in advance.
Oy, had the wrong version of rails in my gemfile.
If anyone else finds this, make sure running rails -v has your intended result! I was receiving an error when trying to see my rails version, and then changing my gemfile solved the issue.

migration error with rake db:migrate

I created a new model, but when I run the rake db: migrate command, it shoots me the following error:
rake aborted!
Gem::LoadError: You have already activated rake 10.4.0, but your Gemfile requires rake
10.3.2. Prepending `bundle exec` to your command may solve this.
/Users/yedidyaweiner/projects/music-app/config/boot.rb:4:in `<top (required)>'
/Users/yedidyaweiner/projects/music-app/config/application.rb:1:in `<top (required)>'
/Users/yedidyaweiner/projects/music-app/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/Users/yedidyaweiner/projects/music-app/config/boot.rb:4:in `<top (required)>'
/Users/yedidyaweiner/projects/music-app/config/application.rb:1:in `<top (required)>'
/Users/yedidyaweiner/projects/music-app/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
What am I doing wrong?
use
bundle exec rake db:migrate
You can also update your gems by running
bundle update
Execute the below commands
a) delete your Gemfile.lock file
b)bundle install
It should update Gemfile.lock with correct rake.
OR
a) gem uninstall rake -v 10.4.0
b) gem install rake -v 10.3.2
then try running 'rake db:migrate'. it should work.

Rubymine rake task debugging

I'm trying to debug rake task in rubymine. I created debug configuration for this task. Ruby SDK I chose project SDK. When I try to run this I got:
Gem::LoadError: You have already activated rake 10.2.2, but your Gemfile requires rake 10.1.1. Prepending `bundle exec` to your command may solve this.
/home/arkency/RubyProject/trainer/config/boot.rb:6:in `<top (required)>'
/home/arkency/RubyProject/trainer/config/application.rb:1:in `<top (required)>'
/home/arkency/RubyProject/trainer/Rakefile:5:in `<top (required)>'
/home/tomek/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/lib/ruby-debug-ide.rb:86:in `debug_load'
/home/tomek/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/lib/ruby-debug-ide.rb:86:in `debug_program'
/home/tomek/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/bin/rdebug-ide:110:in `<top (required)>'
When I run task from terminal all works fine. I don't know from where rubymine takes this rake gem. How to check it? How to change to use the proper Gem? Thanks for all answers.
Click Run => Debug => Edit Configurations, select Bundler tab and check the Run the script in context of the bundle

ruby net/ssh failing to execute rake commands remotely

Hi I'm trying to use the ruby net/ssh gem (2.0.24) to connect to a remote server and run a rake task. I can run other simple tasks using the script outlined below, but rake is failing.
This is my code
Net::SSH.start("myremote_server", 'ubuntu', :keys => ['abcdef.pem'], :paranoid => false, :verbose => :debug) do |ssh|
result = ssh.exec!("cd a_rails_directory; rake sunspot:solr:start")
puts result
ssh.loop
end
and I get the following error message
rake aborted!
uninitialized constant Bundler
/home/ubuntu/a_rails_directory/config/boot.rb:9:in `rescue in <top (required)>'
/home/ubuntu/a_rails_directory/config/boot.rb:5:in `<top (required)>'
/home/ubuntu/a_rails_directory/config/application.rb:1:in `<top (required)>'
/home/ubuntu/a_rails_directory/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
I can run the rake taks quite easily when I ssh-into the remote server manually, but it doesn't work with net/ssh as I've outlined above.
Somehow, I feel like I'm not connecting with the proper shell or the proper access to the path variables, but I'm not sure and I don't know how to fix it either.
Any thoughts?
TIA
never mind. figured out how to load the relevant ruby path info
result = ssh.exec!("[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\" ; cd rails_directory; rake sunspot:solr:start")

Resources