create a lib/tasks/seed_post.rake
the name of the file doesn't matter
and put the following code in it
namespace :seed do
task :posts => :environment do
50.times do |i|
# it's your own problem to generate the following user, params so that it works
Post::CreationService.perform(user, params)
end
end
end
now you can call the task using.. rake seed:posts
or zeus rake seed:posts
or bundle exec rake seed:posts
depending whether you are using zeus or bundler or whatever...
what really matters is that your call should be in the form of
rake namespace_you_defined:task_name_you_defined
also you have to change the controller create to become
def create
@post = Post::CreationService.perform(current_user, post_params)
# instead of this old code i'm assuming you are using
@post = current_user.posts.create!(post_params)
...
end
also add a this file
# app/services/post/creation_service.rb
class Post::CreationService
def self.perform(current_user, params)
current_user.posts.create!(params)
end
end