rake-task

run rake task inside rails application

天大地大妈咪最大 提交于 2019-12-22 17:37:32
问题 I want to run asset precompile task inside the rails application,As I had many dependencies who will change the code,in that case all the time whenever they change i need to run the script as I cant give server access to them so I am providing the GUI for them from that they alone can run the script,so,I have built UI to run the task with some parameter like system("Template='#{params[:template]}' Theme='#{params[:theme]}' rake assets:precompile) I am getting two values from UI(params[

Rails: rake db:test:prepare Vs rake test:prepare

↘锁芯ラ 提交于 2019-12-22 04:06:45
问题 AS the guides, the command used to prepare test database is bundle exec rake db:test:prepare However, I have found that following command also works & created the test db for me. bundle exec rake test:prepare Wanted to know if this is a valid command, if yes. Where can I find the documentation. tested on rails 3.2.8 回答1: According to github and the source code task 'test:prepare' => 'db:test:prepare' is mentioned at the bottom. Hence it's a shortcut, wrapper, whatever you want to call it.

How to execute commands within Rake tasks?

老子叫甜甜 提交于 2019-12-22 01:27:22
问题 I have the rake tasks in my rails application. i want to run a commandline commands with in rake task. how can i do this. i tried by the following but fails desc "Sending the newsletter to all the users" task :sending_mail do run "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v" system "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v &" end The above run command throws run method undefined & System command not throwing any errors but not executed. 回答1: This links may help you run

rake aborted! uninitialized constant Object::Country, why can't see model?

一世执手 提交于 2019-12-19 21:45:39
问题 I have rails 3.1, I am trying to populate data with seeds.rb I have a model Country which is migrated into a countries table But it seems that rails can't see Country model from seeds.rb I get this error: rake aborted! uninitialized constant Object::Country Tasks: TOP => db:seed my seeds.rb file looks like this: # encoding: UTF-8 Country.delete_all my Country model: class Country < ActiveRecord::Base has_many :students has_many :instructors end any idea please ? EDIT I am in development

Why is my rake task running twice in my test?

ε祈祈猫儿з 提交于 2019-12-19 07:35:20
问题 I have a rake task test that I setup following the only examples I could find online. It looks like this: require 'test_helper' require 'minitest/mock' require 'rake' class TestScrapeWelcome < ActiveSupport::TestCase def setup Rake.application.init Rake.application.load_rakefile @task = Rake::Task['scrape:scrape'] @task.reenable end def teardown Rake::Task.clear end test "scraping text and sending to elasticsearch" do mocked_client = Minitest::Mock.new get_fixtures.each_with_index do |arg,i|

PG undefinedtable error relation users does not exist

给你一囗甜甜゛ 提交于 2019-12-17 03:00:10
问题 I saw this question up before, but only for rspec. I haven't created test yet because it's too advanced for me but one day soon i will! :P I get this error when I try to sign-up/login into my app. I used devise to create user and also omniauth2 to sign-in with google . this is the error ActiveRecord::StatementInvalid at /users/auth/google_oauth2/callback PG::UndefinedTable: ERROR: relation "users" does not exist LINE 5: WHERE a.attrelid = '"users"'::regclass ^ : SELECT a.attname, format_type

How to include ActionMailer class in rake task?

本小妞迷上赌 提交于 2019-12-13 11:57:02
问题 I want to use ActionMailer in my rake task in order to send emails to people at a particular time. I have written a mailer class in app/mailers folder like this: class AlertsMailer < ActionMailer::Base default from: 'x@y.com' def mail_alert(email_addresses, subject, url) @url = '#{url}' mail(to: email_addresses, subject: 'Alert') do |format| format.html { render '/alerts/list' } end end end Then I included the following line in my rake task: AlertsMailer.mail_alert(email_addresses, subject)

Rails 3 link_to rake task

空扰寡人 提交于 2019-12-13 03:12:17
问题 I've created a rake task in my application and now I want the task to be accesible for app users from a link on a menu, but I don't know how to invoke it from there. Something like this...? <%= link_to t('backup'), Rake::Task['backup'].invoke %> 回答1: You can't do it. Link_to can link to something static or controller action. So you need to create some action, where you can invoke your Rake Task. class MyTasksController < ApplicationController def rake_it Rake::Task['backup'].invoke end end <%

Log issue in Rails4 with Docker running rake task

痴心易碎 提交于 2019-12-13 01:13:17
问题 My rails4 application is running with docker. It runs a rake task for fetching messages from AWS SQS. The problem I met is that logs can't show up in a console in time . The console doesn't show anything until exception/error comes. In other words, if my application works fine, no logs come to console. But if application went wrong, all the logs(info, warn and error) come together! I already configure the config/production.rb as blow: config.logger = Logger.new(STDOUT) config.logger.level =

How to set up a Rake task for seeding

不羁的心 提交于 2019-12-12 08:54:57
问题 (This is really a newbie question about Rake & Rails & dependencies in general. Trying to wrap my head around how all this fits together) Basically, I want a Rake task that acts like seed.rb but is called separately. It adds test data for the development environment, while my seed.rb provides basic data for all environments. The script, family_seed.rb, uses FactoryGirl to generate some records. It looks like this: require File.expand_path('../../config/environment', __FILE__) require './spec