property_web_builder

https://github.com/etewiah/property_web_builder

Ruby

Create a fully featured real estate website on Rails in minutes! ⛺

Pwb::Seeder.create_photos_from_files

def seed_content(yml_file)
  content_seed_file = Pwb::Engine.root.join('db', 'yml_seeds', yml_file)
  content_yml = YAML.load_file(content_seed_file)
  # tag is used to group content for an admin page
  # key is camelcase (js style) - used client side to identify each item in a group of content
  content_yml.each do |single_content_yml|
    # check content does not already exist
    next if Pwb::Content.where(key: single_content_yml['key']).count > 0
    photos = []
    if single_content_yml["photo_urls"].present?
      photos = create_photos_from_urls single_content_yml["photo_urls"], Pwb::ContentPhoto
      single_content_yml.except! "photo_urls"
    end
    if single_content_yml["photo_files"].present?
      photos = create_photos_from_files single_content_yml["photo_files"], Pwb::ContentPhoto
      single_content_yml.except! "photo_files"
    end
    new_content = Pwb::Content.create!(single_content_yml)
    next unless !photos.empty?
    photos.each do |photo|
      new_content.content_photos.push photo
    end
  end
  print("success!")
end

Source | Google | Stack overflow

Edit

git clone [email protected]:etewiah/property_web_builder.git

cd property_web_builder

open lib/pwb/seeder.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Pwb--Seeder-create_photos_from_files-for-pr


# Commit to git

git add lib/pwb/seeder.rbgit commit -m "better docs for Pwb::Seeder.create_photos_from_files"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Pwb--Seeder-create_photos_from_files-for-pr

hub pull-request


# Celebrate!