Today, I worked on my second rails project application that I wanted to build. I was able to iterate over the unsplash gem and display the photos on the index page. YAY! Now to get everything else going!
Here is the link to my github repo:
rails db:drop rails db:create rails db:migrate rails db:migrate:status
Google:rails console not working https://stackoverflow.com/questions/24276033/rails-console-doesnt-start spring stop rails console
I want to create a simple rails app that will allow users to:
- Search for images to add to their page - sers can have a profile picture (active storage)
- Follow eachother
- Add pictures from other pages to their own.
First create users and Devise gem Cancancan Users can follow eachother Users can add photos to their page Users can search for photos Users can sign in using google, twitter, or github https://source.unsplash.com/1600x900/?nature,water Inspirational quote with photo?
#rails g resource User name:string #rails g resource Follow follower_id:integer followee_id:integer
Steps taken to build:
- rails new photo_app --database=postgresql
- cd photo_app
- rails g resource User name:string
- rails g resource Follow follower_id:integer followee_id:integer
- rake db:drop db:create db:migrate
rails d resource User name:string rails d resource Follow
- gem 'devise'
- rails generate devise:install
- rails generate devise User
I was able to get the photos by iterating over the object provided by the unsplash gem by doing the following:
photos = Unsplash::Photo.search("cats") @photos =  photos.each do |a| description = a["alt_description"] portfolio = a["portfolio_url"] photo = a["urls"].full @photos << photo end
Then I was able to display the photos by adding this code to my views:
<div class="cards"> <% @photos.each do |photo| %> <div class="card"> <img src="<%= photo %>" alt="random" > <br/> <div><p> <%= @quote %> </p></div> </div> <% end%> </div>
The next step is to add a checkbox to my views that will send the information to the photos controller and save it to the database.
Thanks for reading!
Song of the day: