-
-
Save firmanm/2a1e86353536a711b412679e3ec1aa0d to your computer and use it in GitHub Desktop.
Revisions
-
ssaunier revised this gist
Mar 17, 2016 . 1 changed file with 16 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -119,4 +119,20 @@ To display the product photos in the view, add: <% @product.photos.each do |photo| %> <%= cl_image_tag photo.path %> <% end %> ``` ## Bonus - Devise If you want to add an `avatar` to the `User` model, you need to sanitize regarding the strong params: ```ruby # app/controllers/application_controller class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:avatar]) devise_parameter_sanitizer.permit(:account_update, keys: [:avatar]) end end ``` -
ssaunier revised this gist
Mar 17, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -87,7 +87,7 @@ To display the product photo in the view, add: <% end %> ``` ## Multiple pictures per model You need to update the model: -
ssaunier revised this gist
Mar 17, 2016 . 1 changed file with 93 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,6 @@ First add the following gems to your `Gemfile`: ```ruby # Gemfile gem "attachinary" gem "jquery-fileupload-rails" gem "coffee-rails" @@ -24,8 +23,100 @@ Open your `config/application.rb` and add this line after all the `require`: require "attachinary/orm/active_record" ``` Open the `config/routes.rb` file and add this as first line in the `draw` block: ```ruby mount Attachinary::Engine => "/attachinary" ``` Open `app/views/layout/application.html.erb` and append this line after the main `javascript_include_tag`: ```erb <%= cloudinary_js_config %> ``` Open `app/assets/javascripts/application.js` and append these lines before the `require_tree`: ```js //= require jquery-fileupload/basic //= require cloudinary/jquery.cloudinary //= require attachinary ``` Create a file `app/assets/javascripts/init_attachinary.js` and copy-paste those lines: ``` $(document).ready(function() { $('.attachinary-input').attachinary(); }); ``` # Usage ## One picture per model You need to update the model: ```ruby class Product < ApplicationRecord has_attachment :photo # [...] end ``` And the form (`simple_form` gem used): ```erb <%= f.input :photo, as: :attachinary %> ``` And the controller for strong params: ```ruby def product_params params.require(:product).permit(:name, :description, :photo) end ``` To display the product photo in the view, add: ```erb <% if @product.photo? %> <%= cl_image_tag @product.photo.path %> <% end %> ``` ## Multiple attachments per model You need to update the model: ```ruby class Product < ApplicationRecord has_attachments :photos, maximum: 2 # Be carefule with `s` # [...] end ``` And the form (`simple_form` gem used): ```erb <%= f.input :photos, as: :attachinary %> ``` And the controller for strong params: ```ruby def product_params params.require(:product).permit(:name, :description, photos: []) end ``` To display the product photos in the view, add: ```erb <% @product.photos.each do |photo| %> <%= cl_image_tag photo.path %> <% end %> ``` -
ssaunier revised this gist
Mar 17, 2016 . No changes.There are no files selected for viewing
-
ssaunier renamed this gist
Mar 17, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Attachinary Setup First add the following gems to your `Gemfile`: ```ruby -
ssaunier created this gist
Mar 17, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ First add the following gems to your `Gemfile`: ```ruby # Gemfile gem "cloudinary" gem "attachinary" gem "jquery-fileupload-rails" gem "coffee-rails" ``` Then open the terminal and launch: ```bash bundle install rails attachinary:install:migrations rails db:migrate ``` Open your `config/application.rb` and add this line after all the `require`: ```ruby require "attachinary/orm/active_record" ``` Open the `config/routes.rb` file and add this as first line in the `draw` block. ```ruby mount Attachinary::Engine => "/attachinary" ```