diff --git a/app/assets/javascripts/home.js.coffee b/app/assets/javascripts/home.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/home.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/home.css.scss b/app/assets/stylesheets/home.css.scss new file mode 100644 index 0000000..df56f89 --- /dev/null +++ b/app/assets/stylesheets/home.css.scss @@ -0,0 +1,17 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +html { + font-size: 100%; + font-family: 'Helvetica Neue', 'Arial', sans-serif; +} + +header, main { + max-width: 60rem; + margin: 0 auto; +} + +header { + text-align: right; +} diff --git a/app/assets/stylesheets/images.css.scss b/app/assets/stylesheets/images.css.scss index 8d74c21..c55ef10 100644 --- a/app/assets/stylesheets/images.css.scss +++ b/app/assets/stylesheets/images.css.scss @@ -1,3 +1,11 @@ // Place all the styles related to the images controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +ul.images { + list-style: none; + padding-left: 0; + li { + display: inline-block; + } +} diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..4a86fed --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ +class HomeController < ApplicationController + def index + redirect_to user_images_path + end +end diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index a6804ff..681fc38 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -2,5 +2,24 @@ class ImagesController < ApplicationController before_action :authenticate_user! def index + @images = @current_user.images + end + + def create + @image = Image.create(permitted_params) + @current_user.images << @image + redirect_to user_images_path + end + + def destroy + image = @current_user.images.find(params[:id]) + image.destroy + redirect_to user_images_path + end + + private + + def permitted_params + params.require(:image).permit(:user_id, :image) end end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/models/image.rb b/app/models/image.rb index 1b6d3d7..379ff1a 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -1,2 +1,7 @@ class Image < ActiveRecord::Base + dragonfly_accessor :image + + validates :image, presence: true + + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index acbf24a..3745d97 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,8 @@ class User < ActiveRecord::Base dragonfly_accessor :avatar + has_many :images + def self.find_or_create_from_auth(auth) find_by(auth.slice(:provider, :uid)) || create_from_auth(auth) end diff --git a/app/views/images/index.html.erb b/app/views/images/index.html.erb index e69de29..18a92c7 100644 --- a/app/views/images/index.html.erb +++ b/app/views/images/index.html.erb @@ -0,0 +1,18 @@ +