rake

How do I run Rake tasks within a Ruby script?

拜拜、爱过 提交于 2019-12-17 08:33:14
问题 I have a Rakefile with a Rake task that I would normally call from the command line: rake blog:post Title I'd like to write a Ruby script that calls that Rake task multiple times, but the only solution I see is shelling out using `` (backticks) or system . What's the right way to do this? 回答1: from timocracy.com: require 'rake' def capture_stdout s = StringIO.new oldstdout = $stdout $stdout = s yield s.string ensure $stdout = oldstdout end Rake.application.rake_require 'metric_fetcher', ['../

How do I run Rake tasks within a Ruby script?

大城市里の小女人 提交于 2019-12-17 08:32:12
问题 I have a Rakefile with a Rake task that I would normally call from the command line: rake blog:post Title I'd like to write a Ruby script that calls that Rake task multiple times, but the only solution I see is shelling out using `` (backticks) or system . What's the right way to do this? 回答1: from timocracy.com: require 'rake' def capture_stdout s = StringIO.new oldstdout = $stdout $stdout = s yield s.string ensure $stdout = oldstdout end Rake.application.rake_require 'metric_fetcher', ['../

Run rake task in controller

有些话、适合烂在心里 提交于 2019-12-17 05:41:27
问题 I'd like to run a rake task in my controller. Is there any way to do this? 回答1: I agree with ddfreynee, but in case you know what you need code can look like: require 'rake' Rake::Task.clear # necessary to avoid tasks being loaded several times in dev mode Sample::Application.load_tasks # providing your application name is 'sample' class RakeController < ApplicationController def run Rake::Task[params[:task]].reenable # in case you're going to invoke the same task second time. Rake::Task

How do I run a rake task from Capistrano?

不羁的心 提交于 2019-12-17 05:34:55
问题 I already have a deploy.rb that can deploy my app on my production server. My app contains a custom rake task (a .rake file in the lib/tasks directory). I'd like to create a cap task that will remotely run that rake task. 回答1: A little bit more explicit, in your \config\deploy.rb , add outside any task or namespace: namespace :rake do desc "Run a task on a remote server." # run like: cap staging rake:invoke task=a_certain_task task :invoke do run("cd #{deploy_to}/current; /usr/bin/env rake #

Rails DB Migration - How To Drop a Table?

淺唱寂寞╮ 提交于 2019-12-17 03:45:46
问题 I added a table that I thought I was going to need, but now no longer plan on using it. How should I remove that table? I've already run migrations, so the table is in my database. I figure rails generate migration should be able to handle this, but I haven't figured out how yet. I've tried: rails generate migration drop_tablename but that just generated an empty migration. What is the "official" way to drop a table in Rails? 回答1: You won't always be able to simply generate the migration to

Rails DB Migration - How To Drop a Table?

五迷三道 提交于 2019-12-17 03:45:04
问题 I added a table that I thought I was going to need, but now no longer plan on using it. How should I remove that table? I've already run migrations, so the table is in my database. I figure rails generate migration should be able to handle this, but I haven't figured out how yet. I've tried: rails generate migration drop_tablename but that just generated an empty migration. What is the "official" way to drop a table in Rails? 回答1: You won't always be able to simply generate the migration to

What does bundle exec rake mean?

吃可爱长大的小学妹 提交于 2019-12-16 22:24:24
问题 What does bundle exec rake db:migrate mean? Or just bundle exec rake <command> in general? I understand that bundle takes care of maintaining things in the Gemfile. I know what the word "exec" means. I understand that rake maintains all the different scripty things you can do, and I know that db:migrate is one of those. I just don't know what all these words are doing together. Why should bundle be used to execute rake to execute a database migrate? 回答1: bundle exec is a Bundler command to

Why does Ruby 1.9.2 remove “.” from LOAD_PATH, and what's the alternative?

孤人 提交于 2019-12-16 20:43:19
问题 The latest changesets to Ruby 1.9.2 no longer make the current directory . part of your LOAD_PATH . I have a non-trivial number of Rakefiles that assume that . is part of the LOAD_PATH , so this broke them (they reported "no such file to load" for all require statements that based off the project path). Was there a particular justification for doing this? As for a fix, adding $: << "." everywhere works, but seems incredibly hacky and I don't want to do that. What's the preferred way to make

Any advice on using gsub? Works fine in irb console, but won't do find/replace in actual files

不打扰是莪最后的温柔 提交于 2019-12-14 03:03:56
问题 I’ve got some a basic framework for a webapp (some static pages, user authentication, basic testing with rpec). I’d like to use this as a foundation for future webapps. I’ve named my project “framework,” so if I fork it, I’ll have about a dozen instances where I have to replace the term “Framework” with the name of the new app I’m creating. This project is as github.com/bnd5k/framework. The README file contains a list of the files where I need to make the change. I can make those changes by

“FATAL: role ”root“ does not exist” when running rake db:schema:load

五迷三道 提交于 2019-12-14 03:03:48
问题 i finished developing a little app, and try to put it into production. I copied the app to a new folder, created a new psql database with a new user, adjusted my database.yml file and try to run rake db:schema:load to get my database in the right state. Rake is able to connect to my db, since the first steps are executed, but after those, it aborts with the following message. As far as google tells me, it should be an issue with the user. However, since rake can execute the first steps, i