Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- source 'https://rubygems.org'
- # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
- gem 'rails', '4.1.7'
- # Use sqlite3 as the database for Active Record
- gem 'sqlite3'
- # Use SCSS for stylesheets
- gem 'sass-rails', '~> 4.0.3'
- # Use Uglifier as compressor for JavaScript assets
- gem 'uglifier', '>= 1.3.0'
- # Use CoffeeScript for .js.coffee assets and views
- gem 'coffee-rails', '~> 4.0.0'
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
- # gem 'therubyracer', platforms: :ruby
- # Use jquery as the JavaScript library
- gem 'jquery-rails'
- # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
- gem 'turbolinks'
- # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
- gem 'jbuilder', '~> 1.2'
- group :doc do
- # bundle exec rake doc:rails generates the API under doc/api.
- gem 'sdoc', require: false
- end
- # Paperclip gem for managing file uploads
- gem 'paperclip', '~> 3.0'
- gem 'tzinfo-data', platforms: [:x64_mingw, :mingw, :mswin]
- # Use ActiveModel has_secure_password
- # gem 'bcrypt-ruby', '~> 3.0.0'
- # Use unicorn as the app server
- # gem 'unicorn'
- # Use Capistrano for deployment
- # gem 'capistrano', group: :development
- # Use debugger
- # gem 'debugger', group: [:development, :test]
- <table>
- <thead>
- <tr>
- <th>Name</th>
- <th>Original Avatar</th>
- <th>Thumbnail Avatar</th>
- <th>Resume Filename</th>
- </tr>
- </thead>
- <tbody>
- <% @users.each do |user| %>
- <tr>
- <td><%= user.name %></td>
- <!-- display the avatar in both the original size and the thumbnail size -->
- <td><%= image_tag user.avatar.url %></td>
- <td><%= image_tag user.avatar.url(:thumb) %></td>
- <!-- show the filename for the resume -->
- <td><%= user.resume_file_name %></td>
- </tr>
- <% end %>
- </tbody>
- </table>
- <br>
- <%= link_to 'New User', new_user_path %>
- <h1>New user</h1>
- <%= render 'form' %>
- <%= link_to 'Back', users_path %>
- <%= form_for(@user) do |f| %>
- <% if @user.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
- <ul>
- <% @user.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
- <div class="field">
- <%= f.label :name %><br>
- <%= f.text_field :name %>
- </div>
- <!-- Upload your attachments via a simple file_fields in the form -->
- <div class="field">
- <%= f.label :avatar %><br>
- <%= f.file_field :avatar %>
- </div>
- <div class="field">
- <%= f.label :resume %><br>
- <%= f.file_field :resume %>
- </div>
- <div class="actions">
- <%= f.submit %>
- </div>
- <% end %>
- class UsersController < ApplicationController
- # GET /users
- def index
- @users = User.all
- end
- # GET /users/new
- def new
- @user = User.new
- end
- # POST /users
- def create
- @user = User.new(user_params)
- if @user.save
- redirect_to action: 'index', notice: 'User was successfully created.'
- else
- render action: 'new', alert: 'User could not be created'
- end
- end
- private
- # Never trust parameters from the scary internet, only allow the white list through.
- def user_params
- params.require(:user).permit(:name, :avatar, :resume)
- end
- end
- class User < ActiveRecord::Base
- #specify that the avatar is a paperclip file attachment
- #specify additional styles that you want to use in views or eslewhere
- has_attached_file :avatar, :styles => {:thumb => "100x100>"}
- #specify that the resume is a paperclip file attachment
- has_attached_file :resume
- end
- Rails.application.configure do
- # Settings specified here will take precedence over those in config/application.rb.
- # In the development environment your application's code is reloaded on
- # every request. This slows down response time but is perfect for development
- # since you don't have to restart the web server when you make code changes.
- config.cache_classes = false
- # Do not eager load code on boot.
- config.eager_load = false
- # Show full error reports and disable caching.
- config.consider_all_requests_local = true
- config.action_controller.perform_caching = false
- # Don't care if the mailer can't send.
- config.action_mailer.raise_delivery_errors = false
- # Print deprecation notices to the Rails logger.
- config.active_support.deprecation = :log
- # Raise an error on page load if there are pending migrations.
- config.active_record.migration_error = :page_load
- # Debug mode disables concatenation and preprocessing of assets.
- # This option may cause significant delays in view rendering with a large
- # number of complex assets.
- config.assets.debug = true
- # Adds additional error checking when serving assets at runtime.
- # Checks for improperly declared sprockets dependencies.
- # Raises helpful error messages.
- config.assets.raise_runtime_errors = true
- Paperclip.options[:command_path] = 'C:Program FilesImageMagick-6.9.0-Q16'
- # Raises error for missing translations
- # config.action_view.raise_on_missing_translations = true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement