w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Rails + Rake: How to simulate running of rake task to see if it works?
Yes you can actually run bundle exec rake COMMAND -n Having a look at rakes help we can see it here. # rake --help --dry-run Do a dry run without executing actions.

Categories : Ruby On Rails

Send command to running node process, get back data from inside the app
Use repl module. There are examples in the doco doing exactly what you need: run JS in the context of your application and return output.

Categories : Node Js

Core dump while running 'rake rails:update:bin' during Rails 4 upgrade
Problem solved. I had been using the bundle binstubs option in Rails 3.2 and I hadn't deleted the project's bundle and bin dirs prior to the upgrade. After deleting these dirs and re-running bundle install, then running rake rails:update:bin the problem was solved.

Categories : Misc

Running Rake Task with Clock Process
Answer after long time :) but you need to add Procfile to work clockworker gem with heroku this question may help you.

Categories : Ruby On Rails

How to create a new process with command line arguments and give the PID to the parent process?
You can use createprocess() function in windows. Its signature is below BOOL WINAPI CreateProcess( _In_opt_ LPCTSTR lpApplicationName, _Inout_opt_ LPTSTR lpCommandLine, _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ BOOL bInheritHandles, _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment, _In_opt_ LPCTSTR lpCurrentDirectory, _In_ LPSTARTUPINFO lpStartupInfo, _Out_ LPPROCESS_INFORMATION lpProcessInformation ); Example: STARTUPINFO si; PROCESS_INFORMATION pi; //This structure has process id ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); if( argc != 2 ) { printf("Usage: %s [

Categories : C++

Cancan and console command "rake routes"
You definitely need to write it by yourself (I don't know if there are cancan plugins for this). First, cancan doesn't store what you can and cannot access in a specific place connected to routes, cancan only allows you to choose which method you can access for a given class or instance, like can :read, User, it's not tied in any way to the routes and at the same time routes are not tied directly to models (they are tied to controllers). Based on this, it's also not that easy to write such a thing (not impossible, but not easy and I don't think is short). Your best bet is try to emulate tests, you may try to access each route (you can probably parse the output of rake routes or read how that code is generated) with a given user and if the user can't access that path, you mark as non-acc

Categories : Ruby On Rails

rake directory command silently fails?
So the answer was I had misunderstood how rake is supposed to work. To achieve what I wanted I needed to declare a task that had a dependency on the testdata1 directory. e.g. task :default => [ 'testdata1/x.tmp' ] do end directory "testdata1" file "testdata1/x.tmp" => ["testdata1"] do cp "x.tmp", "testdata1/x.tmp" end This of course creates a file_creation task x.tmp which depends on the testdata1 directory, and a default task that depends on the x.tmp file creation task. I feel dumb.

Categories : Misc

Using Start-Process for starting a process having its full command line
Do you need start-process? Can you invoke the executable directly? & "C:Dir 1Dir 2executable.exe" -arg1 "value 1" -arg2 "value 2" See help about_Operators and for info on & (call) operator. Bill

Categories : Powershell

What is rake and how it is used in rails?
Rake is a "software task management tool", similar to Make, etc. in other systems. See: http://guides.rubyonrails.org/command_line.html#rake Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and .rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other. You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks. Each task has a description, and should help you find the thing you need. It is most often used for administration level tasks that can be scripted. The benefit to using Rake over Make or similar, is that it is a Ruby tool and can interface with your RoR

Categories : Ruby On Rails

How to pipe the output of shell command to from a rake task
Rakefile require 'rake' task :shell_me do sh './blah' end blah (executable via chmod +x blah + shebang) #!/usr/bin/ruby puts "HI!" Shell command: $ rake shell_me > blah.log blah.log: HI!

Categories : Shell

can't run rake or rails console on vps
I got it to work by specifying the production environment when I ran the commands RAILS_ENV=production rails console RAILS_ENV=production rake db:seed I found this unusual since the app was working.

Categories : Ruby On Rails

Rails 3.2: rake 10.0.3 required
You either need to run the command in the context of the bundle (recommended): > bundle exec rake db:version Or you need to uninstall the offending rake gem version. > gem uninstall rake > # pick version 10.1.0 from the offered choices.

Categories : Ruby On Rails

Rake tasks inside gem not being found
Fixed it on my end. In the gemspec, you need to include the rake tasks files as well, not just the lib files: Instead of: s.files = Dir['lib/**/*.rb'] Use: s.files = Dir['lib/**/*.rb'] + Dir['tasks/*.rake']

Categories : Ruby On Rails

How to issue a command from the command line of a process running on Linux
If you don't mind waiting for the calls to finish (one at a time) before returning control to your program, you can use the subprocess library. If you want to start something running and not wait for it to finish, you can use the multiprocessing library.

Categories : Python

The "rake" command gets the error "no such file to load -- rspec/core/rake_task"
That learning project requires bundler. You know this because at the project's root path there is a file called Gemfile So in order to continue, first install bundler then run bundle install then rake: $ gem install bundler rubygems-bundler --no-rdoc --no-ri $ bundle install $ rake Prefer a newer Ruby version like 2.0.0 rather than 1.8.7. You can use rvm to get everything setup for you. As a bonus you won't need to install bunder nor rubygems since they are included since ruby 1.9 $ curl -sSL https://get.rvm.io | bash -s stable $ source ~/.rvm/scripts/rvm $ rvm requirements $ rvm install 2.0.0 $ rvm use --default 2.0.0

Categories : Ruby

rails 4.0, rake db:sessions:create
The ActiveRecord session store has been extracted out of Rails into it's own gem as part of Rails move towards better modularity. You need to include the gem as shown below in your Gemfile to get access to the rake task and related functionality. gem 'activerecord-session_store', github: 'rails/activerecord-session_store' The gem The Rails commit where the change happened A bit of an explanation See the README of the gem linked above for more instructions, but you still need run the following command after installing the gem rails generate active_record:session_migration and after that you need to modify the config/initializers/session_store.rb to look like something like this MyApp::Application.config.session_store :active_record_store, :key => '_Application_session' or Ra

Categories : Ruby On Rails

Running Rails code/initializers but not via Rake
The easiest way is checking some environment variable in your initialization code with something like if ENV['need_complex_init'] do_complex_init end and running application with need_complex_init=1 rails s

Categories : Ruby On Rails

Rails rake task doesn't work
You need to add some description to your task: desc "Some description here" task :greet do puts "How are you?" end Easy way to check the presence of the task if you have many tasks: $ rake -T | grep greet

Categories : Ruby On Rails

Rails: rake db:migrate failure `verify_readonly_attribute`
Check this answer: Problem with counter_cache implementation Also you might to take the 2nd advice: find_each instead of each

Categories : Ruby On Rails

Rails deployment - how do you do rake db:reset with capistrano?
You could add the following to your deploy.rb file namespace :custom do task :task do run "cd #{current_path} && bundle exec rake db:reset RAILS_ENV=#{rails_env}" end end Then run cap custom:task to clear the database.

Categories : Ruby On Rails

rake assets:precompile:nodigest in Rails 4
The version of sprockets-rails used in Rails 4.0.0 no longer supports non-digest assets. Per sprocket-rails's Readme: Only compiles digest filenames. Static non-digest assets should simply live in public So any assets that need to be static can be manually put into your public folder. If you need to copy compiled assets such as SCSS files, etc., this rake task may help (source): task non_digested: :environment do assets = Dir.glob(File.join(Rails.root, 'public/assets/**/*')) regex = /(-{1}[a-z0-9]{32}*.{1}){1}/ assets.each do |file| next if File.directory?(file) || file !~ regex source = file.split('/') source.push(source.pop.gsub(regex, '.')) non_digested = File.join(source) FileUtils.cp(file, non_digested) end end

Categories : Ruby On Rails

Running Rake::Pipeline.build inside of Rakefile
Works It looks like one way to handle this is to execute a file, like so: project = Rake::Pipeline::Project.new('Assetfile') # project.clean # Required for rake-pipeline 0.7.0 project.invoke However, this is annoying as I have to create a file for every single rake task. Doesn't Work Looking at the code for Rake::Pipeline it should allow me to pass in a Pipeline, such that this code works: pipeline = Rake::Pipeline.build do output "js" puts Dir.pwd input "js" do match "*.js" do # concatenate all JS files into a single file filter Rake::Pipeline::ConcatFilter, "application.js" end end end project = Rake::Pipeline::Project.new(pipeline) project.invoke Anybody know why this won't work? The error: undefined method `manifest' for nil:NilClass rake-pip

Categories : Ruby

Mixing Rake tasks AND migrations (legacy to new Rails app)
Depending on the complexity of the rake task you could do it all within the migration file. Just be very careful about redefining the models you need to access to avoid any new validations that will fail since those columns don't yet exist. Google for solutions on that. An alternative would be to call the everything from a central rake task that handles this. I'm not sure I like that as much though. One thing to keep in mind... what happens if the rake task fails to migrate some of the data. You need to verify it's all worked before running the migration that deletes the old fields.

Categories : Ruby On Rails

rails crontab rake javascript runtime not find
You need to install nodejs as above gem has an dependancy of it. you will get the list of installation repository links here https://github.com/sstephenson/execjs but as you mentioned nodjs is already installed. you can give the lib and include path while installing gem into your system. and if you are unbuntu user you can install it by a command apt-get install nodejs

Categories : Javascript

How to check if the database exists or not in rails before doing a rake db:setup
Here are some bash scripts I made for this purpose: Postgres if echo "c $PGDATABASE; dt" | psql | grep schema_migrations 2>&1 >/dev/null then bundle exec rake db:migrate else bundle exec rake db:setup fi Mysql if echo "use $MYSQLDATABASE; show tables" | mysql | grep schema_migrations 2>&1 > /dev/null then bundle exec rake db:migrate else bundle exec rake db:setup fi These check for the presence of the schema_migrations table to determine whether rake db:setup has been run previously.

Categories : Ruby On Rails

Ruby-on-Rails Rake import unexpected tASSOC
If you put brackets around your hash in the create method it will work fine: User.create({ :name => row[1], :email => row[2], :password => row[3], :password_confirmation => row[4], :admin => row[5] }) Basically ruby doesn't understand that this is a method call with a hash as the parameter. By putting the brackets there you make it explicit that that is what you mean.

Categories : Ruby On Rails

Ruby-on-Rails Create Record from Rake Task
It seems that your task task :import_users => [:environment] requires another parameter (the environment), try to run it as rake import_users_csv:import_users:development for instance. EDIT: You actually don't have the namespace, your task is called with rake import_users:development

Categories : Ruby On Rails

Rails pending migration in rake db:test:prepare
I suspect the migration for galleries hasn't been executed properly. If you're 100% sure everything is right in your table, you can bump up the migration version to the version of the galleries migration. To do this, find the timestamp of your galleries migration (the 14 numbers in front of your migration file, in this case 20130724211328) and insert this as a new row into the table schema_migrations (which is done automatically by Rails after successfully executing a migration). If the table is empty, you could also drop the table galleries and run rake db:migrate again. This way you can also make sure your migration doesn't trigger any errors.

Categories : Ruby On Rails

Issues creating new Rails app (rake 10.1.0/Bundler failure)
maybe this helps you http://blog.oasic.net/2012/04/solutions-to-invalid-byte-sequence-in.html the problem is not in gems!

Categories : Ruby On Rails

Rails app, installing Devise, rake db:migrate error
I don't think Devise creates a User table. rails generate devise User simply generates a migration that associates Devise with the User table. In your case, the User table does not exist yet. Hence, the error. First, you should write a migration that creates the User table. For example: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| end end end Then run rake db:migrate. Ensure the migration that creates the table is run before db/migrate/20130819025615_add_devise_to_users.rb by naming the file appropriately.

Categories : Ruby On Rails

How to write rake task to create data using excel in rails 3.2
If you do it yourself you have to manage translations yourself, write all the helpers yourself and manage all the data yourself. With a library to do that you save yourself a lot of work and if you need to add or remove regions you can do that quickly and easily. I don't recommend doing it yourself. If you are intent on doing it yourself then your best bet is to save the data in CSV format in a predictable way and read through the CSV creating entries. Assuming your CSV to be something of the format: State,Country Alabama,USA Arkansas,USA ... It would be simple to parse it: require "csv" task :load_states => :environment do CSV.foreach(csv_file, {headers: :first_row}) do |row| state = State.create(name: row["State"]) state.country = Country.where(name: row["Country"]).fi

Categories : Ruby On Rails

How to access variables across multiple rake tasks with Ruby on Rails
You can encapsulate the definition of the user in a helper function. namespace :genie do task :test => :environment do puts test_user.email end task :test_reset => :environment do test_user.update_attributes({ :email => 'test@email.com', }) end end def test_user User.find_or_create_by_username('test') do |i| i.email = email@email.com end end

Categories : Ruby On Rails

Rake Routes and Rails Server both fail to routing issue
The problem WAS the routes. It was these two: get 'sessions#new' get 'posts#new' They have to be: get 'sessions/new' get 'posts/new' That was annoying. Hopefully this helps you.

Categories : Ruby On Rails

Rails: "rake assets:clean" doesn't remove files
try putting this line in application.js '//= require_tree .' and this in application.css '*= require_tree .'? Read more about asset pipelining http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

Categories : Ruby On Rails

Rails: preventing spec files from being initialized during rake tasks
This SO Answer helped me: FactoryGirl screws up rake db:migrate process. This is the specific solution that worked for me. In your gemfile, change factory_girls_rails so it isn't required gem 'factory_girl_rails', :require => false Then require it in your spec helper require 'factory_girl_rails'

Categories : Ruby On Rails

Rails 4 and Heroku - rake assets:precompile trying to call Postgres
There is a gem somewhere that is trying to connect to the database. In my case it was acts_as_taggable_on. I filed a bug with the maintainer. If I commented out the lines in my model that were using it, precompilation worked fine: # acts_as_taggable # accepts_nested_attributes_for :tags If sidekiq is your offender, you can work around this by commenting out the mount statement, precompiling the assets locally, and pushing them to heroku. If the maintainer of the gem fixes the bug, you can then go back to precompiling during slug compilation. Kind of cumbersome, because you have to remember to revert the routes file (i.e. not accidentally commit with the commented-out mount statement).

Categories : Ruby On Rails

Why do i keep getting an error when running rake db:migrate on my fresh rails instance?
In SQLite, index name uniqueness is enforced at the database level. In MySQL you will not reproduce same issue. You can eather change index name or comment this line out (and return while deploing in production), or change database (I mean use mysql instead).

Categories : Ruby

Rails + Rspec: How to test what a rake task "puts" / "print"?
If you're willing to switch from using puts to Logger (which is advisable unless you have a specific reason to use puts), you can test the output in RSpec like this: Rails.logger.should_receive(:info).with('done loading all products')

Categories : Ruby On Rails

Rails server not starting with web sockets and redis options in rake task.
Hey thanks for the question, I personally couldn't get a rake task of mine to post to a websocket channel I had open on my rails server. Your synchronize command helped (along with starting a Redis server locally). Your problem through - seems like you're pointing to 3000. Is that your rails server or the Redis instance? If you're running it locally, I'd omit that line.

Categories : Ruby On Rails

ruby on rails 4: could not find table 'table_name' even after a rake db:test:prepare
Try to recreate your test DB without rbenv RAILS_ENV=test rake db:drop RAILS_ENV=test rake db:create RAILS_ENV=test rake db:test:prepare with rbenv RAILS_ENV=test bundle exec rake db:drop RAILS_ENV=test bundle exec rake db:create RAILS_ENV=test bundle exec rake db:test:prepare

Categories : Ruby On Rails



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.