rake

What does .:format mean in rake routes

守給你的承諾、 提交于 2019-12-31 08:44:21
问题 I type rake routes and I get a bunch of urls like this - /articles/:id(.:format) My question is - what does the .:format mean? It is not clear from the Rails Guides Routing article and there are no other helpful matches for .:format on StackOverflow or google. There is a similar format which is /:controller(/:action(/:id(.:format))) which I also don't understand. Thanks EDIT follow up question - If I wanted to only route HTML pages. Would it be best practice to specify something like .:html

How can I make rake tasks run in an environment other than dev?

强颜欢笑 提交于 2019-12-30 10:29:30
问题 I have a staging machine with a special "staging" environment. I always forget to run rake tasks on that machine like: rake jobs:work RAILS_ENV=staging So instead I end up doing: rake jobs:work And then I'm mystified why nothing has changed in my database. Doh! It's because I didn't remember to supply RAILS_ENV=staging. But I will never, ever need to run anything as the development environment on that server. How can I make rake tasks run in the "staging" environment by default? 回答1: You can

Rails: Make this rake task aware that it is in the test environment

偶尔善良 提交于 2019-12-30 02:50:14
问题 I have the following rake task defined in my lib/tasks folder: namespace :db do namespace :test do task :prepare => :environment do Rake::Task["db:seed"].invoke end end end Now, what this does is seed the test DB when I run rake db:test:prepare . I do this because I have some basic records that must exist in order for the app to function, so they're not optional and can't really be mocked. Separately, I have a model that uses S3 for asset storage in development and production, but I don't

Adding a custom seed file

坚强是说给别人听的谎言 提交于 2019-12-29 02:29:04
问题 I want to populate a new feature with dummy data, but don't want to use the db/seeds.rb file as it already has seeds other data irrelevant for this feature. To run the default seeds.rb file, you run the command rake db:seed . If I create a file in the db directory called seeds_feature_x.rb , what would the rake command look like to run (only) that file? 回答1: Start by creating a separate directory to hold your custom seeds – this example uses db/seeds . Then, create a custom task by adding a

Does Rake task need to run in the background using Resque?

依然范特西╮ 提交于 2019-12-25 16:41:49
问题 I have this code in my rake task. It seems overkill, since the rake task is already being run as a cron job. I think I can safely take it out of Resque and run it directly, but not sure if I missed something. desc "update daily sales" task :daily_sales => :environment do Resque.enqueue(DailySaleService.perform) end 回答1: Yes, it's overkill. There is no reason to use background processing for a rake task; you use background processing to remove heavy lifting from the HTTP request/response cycle

The case of the disappearing ActiveRecord attribute

邮差的信 提交于 2019-12-25 09:28:16
问题 Following the instructions in https://stackoverflow.com/a/24496452/102675 I wound up with the following: namespace :db do desc 'Drop, create, migrate, seed and populate sample data' task seed_sample_data: [:drop, :create, :migrate, :seed, :populate_sample_data] do puts 'Sample Data Populated. Ready to go!' end desc 'Populate the database with sample data' task populate_sample_data: :environment do puts Inspector.column_names.include?('how_to_fix') # create my sample data end end As you would

Whenever gem in rails error :'to_specs': Could not find bundler (>= 0) amongst

☆樱花仙子☆ 提交于 2019-12-25 06:32:04
问题 I am using whenever gem in my application. And i have scheduled a rake task every 5 minutes. But that rake task is not running every 5 minutes. When i saw the log it gave me error like `to_specs': Could not find bundler (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError) this is the content in schedule.rb every 3.minutes do rake "mytask name" end 回答1: I had same issue solved by putting env :PATH, '/bin:/sbin:/usr/bin:/usr

Rake does not swallow RSpec message output

杀马特。学长 韩版系。学妹 提交于 2019-12-25 04:57:09
问题 My spec provides coverage like I had hoped, however, the following 2 messages are displaying in the rspec output: rake resque:scheduler rake environment resque:work How do I swallow these during spec runs so they do not screw up my nyancat formatter? Spec describe 'database rake task' do include_context 'rake' let(:task_paths) { ['tasks/heroku'] } before do invoke_task.reenable end # rubocop:disable all describe 'myapp:heroku' do context ':setup' do context ':secrets' do let(:task_name) {

Mechanize on Ruby 1.9.3 encoding issue

﹥>﹥吖頭↗ 提交于 2019-12-25 04:19:52
问题 Using the following code (from the Mechanize site but in a rake task).. namespace :ans do task :grab => :environment do a = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } begin a.get('http://google.com/') do |page| search_result = page.form_with(:name => 'f') do |search| search.q = 'Hello world' end.submit search_result.links.each do |link| puts link.text end end end end end I get an encoding error.. rake aborted! "\x8B" from ASCII-8BIT to UTF-8 This is whilst using the

Adding devise gem to a Rails 4 / mysql project (table users already exists)

*爱你&永不变心* 提交于 2019-12-25 04:19:12
问题 I'm a total newbie with Ruby, Rails, Rake, MySQL (on Ubuntu/bash/command line) and devise (warden 1.2.3, devise 3.0.4). I must continue with what have been done so far : the Rails 4 project is working and linked to a MySQL database (full, populated with users and data). I'm able to change controllers and views. I must add devise to the project. I'm reading this : https://github.com/plataformatec/devise . My class name is User . So I did rails generate devise User . When I do rake db:migrate I