FAQ Database Discussion Community


rake db:seed yields syntax error, unexpected '\n', expecting => [closed]

ruby-on-rails,ruby,terminal,syntax-error,rake
When I enter rake db:seed in terminal, I receive: SyntaxError: /Users/-/src/-/db/seeds.rb:17: syntax error, unexpected '\n', expecting => Tasks: TOP => db:seed ...where db/seeds.rb has: Category.create(kind: 'Food/Drink') #line 9, everything above is commented out Category.create(kind: 'Entertainment') Category.create(kind: 'Organization') Category.create(kind: 'Business') Category.create(kind: 'Collegiate') Location.create(area: 'Downtown NB') Location.create(area: 'College Ave', Location.create(area: 'Cook/Douglass') #line...

Properly escaping shell arguments in Ruby

ruby,rake,rakefile
Here is the code: desc "Find 301 errors on production servers" task :find301 do command = "grep 'HTTP/1.1\" 301' /var/log/httpd/*ssl-access.log | grep -v 'gclid' | awk '{print \$7}' | sort | uniq -c | sort -nr" production_servers.each do |server| sh "ssh [email protected]#{server} #{command}" end end Is there a better way...

Deployment with Rake Causing Image Permission Errors (600)

ruby,rake,web-deployment,file-permissions
I'm deploying my website to my server with Rake for the first time and I've run into a slight issue. RAKEFILE desc 'Deploying the website...' task :deploy do puts 'Deploying to server.com' user = 'user' server = 'server.com' path = 'server.com/html' sh "rsync -rtzh --delete _site/ #{user}@#{server}:#{path}" puts 'Fin!' end...

Emulation for ERB extention -%> for the purpose of unittests

ruby,rake,chef,erb
I need to evaluate an ERB template, and then ensure it's a valid NGINX configuration file, but vanilla ERB doesn't allow the -%> directive. How am I able to add that extension into my rakefile? I've been able to replicate the problem in irb as so: ~ $ irb irb(main):001:0>...

Rake task variable under namespace

ruby-on-rails,ruby,rake,rake-task
I see a strange thing in my rake script today. I have two Rake tasks under the different namespaces like following: path = "/home/tomcat/tomcat" namespace :stage do path = "/home/tomcat/stage-tomcat" desc "Deploys a java application to stage tomcat" task :java_deploy do puts path # stage:java_deploy should print /home/tomcat/stage-tomcat end end...

Why I get undefined method `meta_keywords' when running rake db:setup?

ruby-on-rails,rake,refinerycms
I get this error: rake aborted! undefined method `meta_keywords' for Page::Translation:0x0000000548d5f0 when running rake db:setup on a refinery cms 1.0.0 rails 3.0.7. and can't quite debug it Edit part of schema: create_table "page_part_translations", :force => true do |t| t.integer "page_part_id" t.string "locale" t.text "body" t.datetime "created_at" t.datetime "updated_at" end add_index...

rake rspec test doesn't run

ruby,rspec,rake
I followed the intro in the rspec page, and then added a test task to my rakefile to make a simple file read test: #Rakefile task default: %w[test] task :test do ruby "spec/file_reader_spec.rb" end #spec/file_reader_spec.rb require './lib/filereader' require 'rspec' RSpec.describe "file_reader" do context "with sample test input file" do it...

How to test system calls from the rake task

ruby,rspec,rake,system,stub
Suppose I have a pretty simple Rake task: task :test do system "bundle exec rspec spec" end I try testing it by stubbing the ::Kernel.system method call: describe "test" do before { allow(::Kernel).to receive(:system) } it "runs 'bundle exec rspec spec'" do expect(::Kernel).to receive(:system).with "bundle exec rspec spec" Rake::Task[:test].invoke end...

Odd rake db:migrate output

ruby-on-rails,ruby,rake,rails-activerecord
Why does rake db:migrate run Execute db:schema:dump my output is all screwed up (showing SQL). Looks like this: ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations" (3.7ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class...

Rails: shell command in controller

ruby-on-rails,ruby,shell,rake,rvm
I'm trying to run shell command with rake task of another project in rails controller: def generate render json: `cd /Users/user/project && rvm use [email protected] && bundle exec rake users:build` end The problem is that not working for that task (nothing happening) but if I run rake routes for example...

Reset database with rake task

ruby-on-rails,heroku,rake
I want to use Heroku's scheduler to reset my database once every day. It's recommended to use rake tasks for the scheduler. This is what I've tried: task :reset_database => :environment do `heroku pg:reset MY_DB:URL` `heroku run rake db:migrate db:seed` # some other ruby commands end But how would I...

Minitest Issues Ruby on Rails

ruby-on-rails,ruby,rake,minitest
I'm reading the Ruby on Rails Tutorial by Michael Hartl and following along. I'm having problems however right when trying to do some testing. [[email protected] twitter-clone]$ bundle exec rake test /media/Data.II/Dropbox/Web Development/odin-project/3. Ruby on Rails/twitter-clone/db/schema.rb doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do...

Confused with the second variable of task : some_random_name1, [:some_random_name2] => :environment in rake?

ruby,syntax,rake
I am new to ruby and rake, and currently confused with some ruby syntax. task :some_random_name1, [:some_random_name2] => :environment do |task, args| end What does [:some_random_name2] here mean? I know some_random_name1 is a task that depends on another task :environment, and task and args in |task, args| are arguments from...

Rake autoloading Gemspec

ruby,rake,gemspecs
I want to know, does rake task autoload a .gemspec? I ask because I'm running a rake task to automate building my gem, part of that is loading files and it prints out messages. I should see: Loading external libraries for rake_tasks instead I see: Loading external libraries for gemspec...

Why does http request fail when running from rake task in a thread?

ruby,multithreading,rake,rake-task
I am trying to figure out why the following code does not work. The response is not printed out and from other research the request fails. task :test_me do t1 = Thread.new do puts 'start' uri = URI.parse("http://google.com/") response = Net::HTTP.get_response(uri) puts response.inspect # this line not getting printed end...

DEPRECATION WARNING while using bundle install

ruby-on-rails,ruby,ruby-on-rails-4,rake,bundler
So I am trying to do bundle install . But it is throwing the below errors. What is the problem here? bundle exec rake db:create:all DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:66) DEPRECATION WARNING: String based terminators are deprecated, please use...

Why doesn't it know how to build this task?

ruby-on-rails,rake,rake-task,rakefile
So I have the following task in rails running on jruby: desc "Creates a new site with args: name, api_url (must be http(s)://api.something.com/v1/ - note the ending slash), api_key" task :add_new_site, [:name, :api_url, :api_key] => :enviroment do | t, args | if !Site.find_by_site_name(args[:name]) new_site = Site.new(site_name: args[:name], site_api_url: args[:api_url], site_api_key:...

rake aborted! wrong number of arguments(1 for 0)

ruby-on-rails,rake
Running rake routes gives out a "wrong number of arguments(1 for 0)" error. Also running rake without any task throws same result. Here is the output for both (rake --trace): Note: this happens even with an empty routes.rb rake version is (10.4.2) ** Invoke default (first_time) ** Invoke test (first_time)...

Cannot add object as hash value in Rake: TypeError: no implicit conversion of DropboxClient into String

ruby,rake,dropbox-api
I use the following code for my DropBox in a Rake task: require 'dropbox_sdk' ENV['DROPBOX_APP_ACCESS_KEY'] = 'access key' ENV['DROPBOX_APP_KEY'] = 'key' ENV['DROPBOX_APP_SECRET'] = 'secret' flow = DropboxOAuth2FlowNoRedirect.new(ENV['DROPBOX_APP_KEY'], ENV['DROPBOX_APP_SECRET']) client = DropboxClient.new(ENV['DROPBOX_APP_ACCESS_KEY']) This part is just how you connect. It's from the API documentation and works fine. What's weird though is...

What's the new assemblyinfo task in Albacore 2.0?

ruby,rake,albacore
I tried to update my build scripts using the latest version of Ruby/Rake and Albacore. Coming from Ruby 2.0.0 Rake 10.1.1 Albacore 0.3.5 I updated the build server to Ruby 2.1.6 Rake 10.4.2 Albacore 2.3.22 I already figured out that 'msbuild' changed to 'build' etc. But I failed to get...

Database Migrations on Secondary Database on Heroku

ruby-on-rails,ruby,database,heroku,rake
Our company acquired an application from another company, so I'm a little unfamiliar with how they may have done this in the past. Currently there are two applications in Heroku. A production and staging app. Below is the basic app setup for clarity. Production App WHITE // Primary database BLACK...

How to access members of another class in a different file

ruby,rake,ruby-prolog
I'm using ruby-prolog. I want to run a task to query a fact. demo.rb: require 'ruby-prolog' c = RubyProlog::Core.new c.instance_eval do person['name','brian'].fact person['name','James'].fact puts 'all the names are: ' p query(person['name', :A]) end This works great. Now I want to run the query inside of Rake. That is a problem...

rake install command is not working (gem 'octopress', '~> 3.0.7')

ruby,ruby-on-rails-4,rake
I am using windows8.1 . I saw some similar post at stackoverflow but I didn't get any solution. C:\Sites\occtopress>bundle exec rake install DL is deprecated, please use Fiddle DL is deprecated, please use Fiddle rake aborted! Don't know how to build task 'install' (See full trace by running task with...

Rails environment variables failing to load in model

ruby-on-rails,model,environment-variables,rake
I have an environment variable that I'm using in two places, one is in a rake task, the other is in a model method. When I call it from the rake task, everything is fine and the variable loads, but when I call it from the model it doesn't find...

Heroku: “Process exited with status 127” after deploying ruby app

ruby-on-rails,ruby,heroku,rake
After deploying some changes to Heroku, I am getting the following error (even if I revert the changes). » heroku web.1 - - Starting process with command `bin/rails server -p 59617 -e production` » app web.1 - - /usr/bin/env: ruby : No such file or directory » heroku web.1 -...

Passing parameters to Rake

ruby,powershell,rake
I have seen the popular post on how to pass parameters to rake. I copy pasted sample code from that post and it is not working for me: Rakefile.rb: require 'rake' task :my_task, [:arg1, :arg2] do |t, args| puts "Args were: #{args}" end Then at the command line I run...

Not setting arguments properly in rails tasks?

ruby-on-rails,ruby,rake,rake-task,rakefile
I am curious as to why my args variable is always coming back as {} in the following task: desc "Create an Api Key assuming one doesn't exist." task :create_api_key, [:name] => :environment do | t, args | if !ApiKey.find_by_application_name(args[:name]) binding.pry if ApiKey.new(:application_name => args[:name], :api_key => SecureRandom.hex(32)).save! puts "Your...

rake -T cannot show my tasks

ruby,rake
Rakefile: require "bundler/gem_tasks" require "workers/access_token_worker" require 'dotenv' Dotenv.load task :default => 'access_token:refresh' namespace :access_token do task :refresh do AccessTokenWorker.work(ENV['WECHAT_APP_ID'], ENV['WECHAT_APP_SECRET']) end end rake -T: rake build # Build wechat-0.1.0.gem into the pkg directory rake install # Build and install wechat-0.1.0.gem into system gems rake install:local # Build and install wechat-0.1.0.gem...

Ruby rails rake not rolling back far enough

migration,rake,rollback
I try "rake db:rollback STEP=6" or more, but when I run "rake db:migrate" it only shows the last migration file being executed: == 20150508040222 CreateStructure: migrating ================================== == 20150508040222 CreateStructure: migrated (0.0000s) ========================= When I try to check if the new fields have been created in the previous step using...

How to create a rake rule that matches files from different folders?

c,gcc,rake
I need to create a rake rule where I compile each C file in the 'src' folder to a corresponding file in the 'obj' folder. In make this is achieved with: obj/%.o: src/%.c I've been trying to figure out how this can be done in rake, but couldn't find a...

Rails 4.2 / PostgreSQL and Test Database Preparation

ruby-on-rails,postgresql,rake
We are using Rake::Task['db:create'].enhance to add a new schema and create an extension in the newly created schema as below. Rake::Task['db:create'].enhance do ActiveRecord::Base.connection.execute('CREATE SCHEMA IF NOT EXISTS shared_extensions;') ActiveRecord::Base.connection.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA shared_extensions;') end Can we enhance the test database preparation in the same way?...

How to diagnose slow rails / rake / rspec tasks

ruby-on-rails,ruby,rspec,rake,rakefile
I always have a significant delay (c.10 seconds) when running tasks like: rails server rake assets:precompile rspec spec The delay is at the point before it says: Connecting to database specified by database.yml I've found several articles identifying 10 or more different parameters that can be tuned to speed up...

Can I extend Go To Definition to go to the ruby web API or code definition?

ruby,rake,sublimetext,sublimetext3
I am running into problems where I cannot tell if the code I'm reading is standard ruby, some gem or in house code. To resolve this I would like to extend the capabilities of Go To Definition. Can I configure or add an extension to sublime that will allow Go...

error changing DB table column from integer to BigInt

ruby-on-rails,sqlite,rake
I am trying to change my table column from an integer to a bigint I create a migration and then added this code to the migration file. class ChangeMileageToBigint < ActiveRecord::Migration def change execute <<-SQL ALTER TABLE posts ALTER COLUMN mileage TYPE bigint USING mileage::bigint SQL end end However, I...

Rake Task vs. Migration for simple DB changes

ruby-on-rails,ruby,rake
Let's say I create a rake task to add a column to a table. After I run that rake task, can I delete the rake file while keeping the changes to the database? I understand that a migration could accomplish this same type of task, but if I want to...

How to use null=>false in a migration file?

ruby-on-rails,rake
I'm changing migration file with create table into add column. This was the part of the original migration file. create_table(:users) do |t| t.string :provider, :null => false t.string :uid, :null => false, :default => "" This is something I wrote. add_column :users, :provider, :string, :null => false add_column :users, :uid,...

Running rails specs using rake command => 0 fails, while running them with rspec command => 1 warning 5 fails

ruby-on-rails,rspec,rake
When I run the specs of my Rails project, I usually use rake, which outputs the following: [email protected]:~/Documents/Work/MuheimWebdesign/base/src (master *)$ rake /Users/josh/.rvm/rubies/ruby-2.1.0/bin/ruby -I/Users/josh/.rvm/gems/[email protected]/gems/rspec-core-3.1.7/lib:/Users/josh/.rvm/gems/[email protected]/gems/rspec-support-3.1.2/lib /Users/josh/.rvm/gems/[email protected]/gems/rspec-core-3.1.7/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb --color --format Fuubar Run options: include {:focus=>true} All examples were...

How do you use multiple tasks using Rake::TestTask?

ruby,testing,rake,minitest,rake-task
I am running Minitest with Rake and would like to have two separate Rake tasks. I have added the following: require 'rake/testtask' task :default => [:test] task :quick => [:unit] Rake::TestTask.new do |t| puts 'within test task' t.libs.push 'specs' t.pattern = 'specs/*_spec.rb' ENV['STACK'] = 'stack1' puts "test stack #{ENV['STACK']}" end...

Intercept WEBrick request

ruby,http,rake,webrick
I have a web app that runs on different pieces of hardware, that for the most part consists of smart TVs and set-top boxes. My web app contains a ruby script to setup the app for local debugging. This script builds my app, listens for file changes, and hosts the...

How to retry a rake task if you get a Bad Gateway error response from a web source

ruby-on-rails,ruby,rake,instagram-api
I am trying to run a rake task to get all the data with a specific tag from Instagram, and then input some of the data into my server. The task runs just fine, except sometimes I'll get an error response. It's sort of random, so I think it just...

Removing a value from seed file in Rails

ruby-on-rails,ruby,postgresql,rake
I have a seed file in my application : friends_seed_data.rb. It consists of these values : ["NEW", "OLD", "DELETED"]. I ran rake db:seed a while ago and I now have these three conditions in my db. Now, I don't need the condition OLD anymore. How should I remove this condition...

Rake not exporting PATH

ruby,path,environment-variables,rake
I would like a Rake task to export the path to my command line tool to $PATH, and so I have the following line in my Rakefile: task :make_path do sh 'export PATH=$HOME/Desktop/folder:$PATH' end When putting that line export PATH=$HOME/Desktop/folder:$PATH into the terminal directly, the path is prepended to my...

Travis CI: The command “bundle exec rake” exited with 1

ruby-on-rails-4,rake,travis-ci
I am having a problem with my Travis build where the build fails with the error The command "bundle exec rake" exited with 1. Here is the build log from Travis. Here is a link to the GitHub repo. I've tried adding require 'bundler' to my Rakefile as suggested by...

Rake db:seed not associating a created object to it's parent model correctly?

ruby-on-rails,ruby,activerecord,rake
I have a User model which has_one Library which has_many Books. In my seeds file I do this: user1 = User.new user1.email = "[email protected]" user1.name = "testname" user1.password = "password" user1.library = Library.new user1.library.save! book1 = Book.create!(hash_of_attributes) user1.library.books << book1 puts "book1 library_id " + book1.library_id.to_s user1.save! the line puts...

Rails rake db:create does not work

ruby-on-rails,ruby,ruby-on-rails-3,rake
I come from a computer science and programming background, and I am familiar with a *nix CLI. I am new to ruby on rails, and I am doing an online bootcamp. One of my lessons has me creating a new rails application. It starts out with the following commands to...

Cannot test my model tests

ruby,ruby-on-rails-4,testing,rake,bundler
I have tests in the folder: test/models/person/helper/age_calculator_test.rb These test should fail because of: assert_equal false, true they do fail when I run: bundle exec m test/models/person/helper/age_calculator_test.rb But when Im running: bundle exec m test/models These Tests are not run! What do I wrong? How can I test all of my...

Rails - can not access table from within rake task

ruby-on-rails,ruby,rake,rake-task
I am trying to create a rake task which querries an API and adds records to a table. However, I can not access that table (I get the following error). ActiveRecord::StatementInvalid: Could not find table 'exchange_rates' My code is: namespace :query_api do task get_currency_values: :environment do exchange_rate = ExchangeRate.new #some...

Authenticating Heroku gem from rake task

ruby-on-rails,heroku,rake
I am trying to get my automatic backup script to work. I am using the heroku gem. The script is being run from Heroku's Scheduler addon. require "heroku/command/pg" require "heroku/command/pg_backups" .... def initialize @client = Heroku::Command::Pg.new([], app: ENV['APP_NAME']) end ... attachment = @client.send(:generate_resolver) ... As soon as I call attachment...

How to exclude files/directories when running a Cucumber Rake task?

ruby,tags,cucumber,rake
I currently have two folders with different features within my scenarios folder: features scenarios folder_1 first_feature.feature folder_2 second_feature.feature Inside these features I have many scenarios that share some different tags first_feature.feature: Feature: One @tag1 @tag2 Scenario: Scenario 1 @tag3 Scenario: Scenario 2 second_feature.feature: Feature: Two @tag1 @tag4 Scenario: Scenario 3...

Rake `directory` does not recursively create folders

ruby,rake
I'm trying out Rake today to build my project, coding along with Jim Weirich's presentation. I have a task create_directories: task :create_directories do directory('build/subfolder') end Now when I execute rake create_directories, it outputs mkdir -p build and the build folder is created, but not the subfolder. Why is the subfolder...

Why does default rake task run specs in Rails app?

ruby-on-rails,ruby,rspec,rake
I have one app that runs the specs with just rake, but don't know where or how this task is defined. There are no tasks in lib/tasks. Part of Gemfile: group :test do gem 'capybara' gem 'guard-rspec' gem 'rspec-rails' gem 'database_cleaner' gem 'launchy' gem 'oauth2' gem 'rack_session_access' gem 'factory_girl' gem...

Rake equivalent of make -j (--jobs)

ruby,multithreading,rake,rakefile
The make commands allows a -j (--jobs) options documented as such: -j [jobs], --jobs[=jobs] Specifies the number of jobs (commands) to run simultaneously. If there is more than one -j option, the last one is effective. If the -j option is given without an argument, make will not limit the...

Rails-way to execute one-off task on Rails server startup

ruby-on-rails,ruby,rake,foreman
I have Rails 4.2 application and I want to execute some one-off code when server starts. My first approach was to use initializer in config/initializers to run the code. But in this case code is being executed also for all the rake tasks and Sidekiq process. So I've created a...

schema.rb file is not updating

ruby-on-rails,postgresql,rake
In my app, I edited a migration file shown here: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :first_name t.string :last_name t.string :dj_alias t.boolean :site_admin t.integer :station_id t.string :byline t.string :bio t.timestamps null: false end end end to have the bio and byline fields. However, when I...

Trying to get a rake task to send an email notification if

ruby-on-rails,ruby-on-rails-4,activerecord,rake
My issue is that every time I try to run rake check_pending I get an error. Can someone please help me and let me know what I might be doing wrong. Any help is greatly appreciated! This is my error rake check_pending rake aborted! NoMethodError: undefined method `find_all_by_approve_disapprove' for Entry...

Rake namespace not recognizing a local task

ruby,rake,rake-task
I am learning Ruby and trying to experiment with parsing arguments and having trouble with this example I made. The Rake namespace is not recognizing a local task. The :example task works fine. The :exampleAlt task is not working. The error is: $ rake myapp:exampleAlt rake aborted! NameError: undefined local...

How do I point to the applications folder?

ruby,osx,rake
How do I point to the applications folder in rake? I tried task :md do mkdir File.join(File.expand_path("~/Applications/My\ App/Folder1/Folder2"),"Folder3") end puts shows that I'm taken to /users/me/Applications instead of my main Applications folder....