This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thin_server = Thread.start do | |
Thin::Server.start('0.0.0.0', 4567) do | |
run Rack::Directory.new( File.join(Dir.pwd,"seed-images") ) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
seed_data = [ | |
{model_name: "somename", image:"my_image.jpg"}, | |
... | |
] | |
seed_data.each do |seed| | |
model = Model.find_by_name(seed[:model_name]) | |
model.remote_image_url="http://localhost:4567/#{model[:image]}" | |
model.save | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thin_server.kill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
seed_data = [ | |
{model_name: "somename", image:"my_image.jpg"}, | |
#... | |
] | |
thin_server = Thread.start do | |
Thin::Server.start('0.0.0.0', 4567) do | |
run Rack::Directory.new( File.join(Dir.pwd,"seed-images") ) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee | |
belongs_to: :department | |
end | |
class Departmet | |
belongs_to :organization | |
has_many :employees | |
end | |
class Organization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
belongs_to :organization through: :department # Does not exist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee | |
belongs_to: :department | |
has_one :organization, through: :department | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Project | |
has_many :project_departments | |
has_many :departments, through: :project_departments | |
end | |
class ProjectDepartment | |
belongs_to :project | |
belongs_to :project | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Project | |
# as above | |
has_one :project_department, ->(department) { where department: department }, class_name: 'ProjectDepartment' | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee | |
belongs_to: :department | |
has_one :organization, through: :department | |
end | |
class Departmet | |
belongs_to :organization | |
has_many :project_departments | |
has_many :projects, through: :project_departments | |
has_many :employees |