Run rake task in controller

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 … Read more

Running ruby debug in rspec?

You will get what you want by including require ‘ruby-debug’ at the top of your spec: # spec/models/user_spec.rb require ‘spec_helper’ require ‘ruby-debug’ describe User do it “should be valid” do debugger User.new.should be_valid end end You would then run rake spec or rspec as normal NOTE: I now prefer Ruby 2.0+ and pry. It is … Read more

Execute bash commands from a Rakefile

I think the way rake wants this to happen is with: http://rubydoc.info/gems/rake/FileUtils#sh-instance_method Example: task :test do sh “ls” end The built-in rake function sh takes care of the return value of the command (the task fails if the command has a return value other than 0) and in addition it also outputs the commands output.

Default task for namespace in Rake

Place it outside the namespace like this: namespace :my_tasks do task :foo do do_something end task :bar do do_something_else end end task :all => [“my_tasks:foo”, “my_tasks:bar”] Also… if your tasks require arguments then: namespace :my_tasks do task :foo, :arg1, :arg2 do |t, args| do_something end task :bar, :arg1, :arg2 do |t, args| do_something_else end end … Read more

Rails: Invalid byte sequence in US-ASCII (Argument Error) when I run rake db:seed

You’re receiving an encoding error because your filesystem isn’t configured to encode the date you’ve added (since presumably it includes new characters – possibly in your HTML entity encoded map URL – that didn’t exist in your prior data seed). The following will should resolve this error by setting the UTF-8 locale on your machine: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)