Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

multiple seeds in rails 6

# lib/tasks/custom_seed.rake
# lib/tasks/custom_seed.rake
namespace :db do
  namespace :seed do

    Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |filename|
      task_name = File.basename(filename, '.rb').intern

      task task_name => :environment do
        load(filename)
      end
    end

    task :all => :environment do
      Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].sort.each do |filename|
        load(filename)
      end
    end

  end
end

# Then, in order to run specific seed file, you can just run
rake db:seed:seed_file_name
#To run all the seeds file with order in that db/seeds folder, run below command
rake db:seed:all

Comment

PREVIOUS NEXT
Code Example
Ruby :: sequel alter table 
Ruby :: next if ruby 
Ruby :: rails render json only some attributes 
Ruby :: how do i fix FATAL: password authentication failed for user "root" 
Ruby :: rails scope alias 
Ruby :: rails admin overwrite view 
Ruby :: $stdout ruby override 
Ruby :: rails add element to array 
Ruby :: ruby get classname 
Ruby :: rails update column without callbacks 
Ruby :: ruby basic arithmetic 
Ruby :: ruby get haft of array 
Ruby :: send email rails c one line 
Ruby :: time_ago_in_words for created_at model in rails 
R :: r - remove scientific notations 
R :: dplyr colnames r 
R :: rmarkdown section title as variable ## 
R :: merge multiple datatable in r 
R :: r bar plot 
R :: custom function in r 
R :: regex in r 
R :: r count distinct dplyr 
R :: calculating RMSE, MAE, MSE, Rsquared manually in R 
R :: How to remove rows with inf from a dataframe in R 
R :: autoplot confusion matrix 
R :: 3d scatter plot in r 
R :: absolute value in r 
R :: select last child with class in r 
R :: find sys date in R 
R :: parent folder for working directory in r 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =