diff --git a/Gemfile b/Gemfile index 23c7bb1..01857cc 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,11 @@ git_source(:github) do |repo_name| "https://github.com/#{repo_name}.git" end +#File uploads rails gem +gem 'carrierwave', '~> 1.0' +#Cloud storage for file uploads, created an account on cloudinary +gem 'cloudinary' + #For different Roles management gem 'rolify' #Authorization gem cancancan for controlling rolify diff --git a/Gemfile.lock b/Gemfile.lock index a480736..210057b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) arel (8.0.0) + aws_cf_signer (0.1.3) bcrypt (3.1.11) bindex (0.5.0) builder (3.2.3) @@ -53,8 +54,15 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + carrierwave (1.2.1) + activemodel (>= 4.0.0) + activesupport (>= 4.0.0) + mime-types (>= 1.16) childprocess (0.8.0) ffi (~> 1.0, >= 1.0.11) + cloudinary (1.8.1) + aws_cf_signer + rest-client coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -71,11 +79,15 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.3) + domain_name (0.5.20170404) + unf (>= 0.0.5, < 1.0.0) erubi (1.7.0) execjs (2.7.0) ffi (1.9.18) globalid (0.4.1) activesupport (>= 4.2.0) + http-cookie (1.0.3) + domain_name (~> 0.5) i18n (0.9.1) concurrent-ruby (~> 1.0) jbuilder (2.7.0) @@ -91,10 +103,14 @@ GEM mail (2.7.0) mini_mime (>= 0.1.1) method_source (0.9.0) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) mini_mime (0.1.4) mini_portile2 (2.3.0) minitest (5.10.3) multi_json (1.12.2) + netrc (0.11.0) nio4r (2.1.0) nokogiri (1.8.1) mini_portile2 (~> 2.3.0) @@ -135,6 +151,10 @@ GEM responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) + rest-client (2.0.2) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) rolify (5.1.0) rspec-core (3.7.0) rspec-support (~> 3.7.0) @@ -191,6 +211,9 @@ GEM thread_safe (~> 0.1) uglifier (3.2.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.4) warden (1.2.7) rack (>= 1.0) web-console (3.5.1) @@ -211,6 +234,8 @@ DEPENDENCIES byebug cancancan (~> 2.0) capybara (~> 2.13) + carrierwave (~> 1.0) + cloudinary coffee-rails (~> 4.2) devise jbuilder (~> 2.5) diff --git a/app/assets/stylesheets/listings.scss b/app/assets/stylesheets/listings.scss index 26576b1..0773f5e 100644 --- a/app/assets/stylesheets/listings.scss +++ b/app/assets/stylesheets/listings.scss @@ -1,3 +1,8 @@ -// Place all the styles related to the Listings controller here. +// Place all the styles related to the listings controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +listing.photo { + width: 10px; + length: 10px; +} diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 154922a..7eb2c71 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,6 @@ class HomeController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_user! def index - + end end diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index a1bd4b4..b655959 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -69,6 +69,6 @@ class ListingsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def listing_params - params.fetch(:listing, {}) + params.require(:listing).permit(:photo, :address, :property_type, :number_of_bedrooms, :number_of_bathrooms, :max_price_per_week, :available_date, :roles) end end diff --git a/app/models/listing.rb b/app/models/listing.rb index c6f31a8..b06447d 100644 --- a/app/models/listing.rb +++ b/app/models/listing.rb @@ -1,2 +1,4 @@ class Listing < ApplicationRecord + mount_uploader :photo, PhotosForListingsUploader + # params.require(:Listing).permit({Photo: []}) end diff --git a/app/uploaders/photos_for_listings_uploader.rb b/app/uploaders/photos_for_listings_uploader.rb new file mode 100644 index 0000000..b261578 --- /dev/null +++ b/app/uploaders/photos_for_listings_uploader.rb @@ -0,0 +1,49 @@ +class PhotosForListingsUploader < CarrierWave::Uploader::Base +# include Cloudinary::CarrierWave + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + # include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_whitelist + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index c83a623..691adb5 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,6 +1,4 @@
Find me in app/views/home/index.html.erb
<%= notice %>
<%= alert %>
+ + <% if user_signed_in? %> +