Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. source 'https://rubygems.org'
  2.  
  3.  
  4. # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
  5. gem 'rails', '4.1.7'
  6.  
  7. # Use sqlite3 as the database for Active Record
  8. gem 'sqlite3'
  9.  
  10. # Use SCSS for stylesheets
  11. gem 'sass-rails', '~> 4.0.3'
  12.  
  13. # Use Uglifier as compressor for JavaScript assets
  14. gem 'uglifier', '>= 1.3.0'
  15.  
  16. # Use CoffeeScript for .js.coffee assets and views
  17. gem 'coffee-rails', '~> 4.0.0'
  18.  
  19. # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  20. # gem 'therubyracer', platforms: :ruby
  21.  
  22. # Use jquery as the JavaScript library
  23. gem 'jquery-rails'
  24.  
  25. # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
  26. gem 'turbolinks'
  27.  
  28. # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
  29. gem 'jbuilder', '~> 1.2'
  30.  
  31. group :doc do
  32. # bundle exec rake doc:rails generates the API under doc/api.
  33. gem 'sdoc', require: false
  34. end
  35.  
  36. # Paperclip gem for managing file uploads
  37. gem 'paperclip', '~> 3.0'
  38. gem 'tzinfo-data', platforms: [:x64_mingw, :mingw, :mswin]
  39. # Use ActiveModel has_secure_password
  40. # gem 'bcrypt-ruby', '~> 3.0.0'
  41.  
  42. # Use unicorn as the app server
  43. # gem 'unicorn'
  44.  
  45. # Use Capistrano for deployment
  46. # gem 'capistrano', group: :development
  47.  
  48. # Use debugger
  49. # gem 'debugger', group: [:development, :test]
  50.  
  51. <table>
  52. <thead>
  53. <tr>
  54. <th>Name</th>
  55. <th>Original Avatar</th>
  56. <th>Thumbnail Avatar</th>
  57. <th>Resume Filename</th>
  58. </tr>
  59. </thead>
  60.  
  61. <tbody>
  62. <% @users.each do |user| %>
  63. <tr>
  64. <td><%= user.name %></td>
  65. <!-- display the avatar in both the original size and the thumbnail size -->
  66. <td><%= image_tag user.avatar.url %></td>
  67. <td><%= image_tag user.avatar.url(:thumb) %></td>
  68.  
  69. <!-- show the filename for the resume -->
  70. <td><%= user.resume_file_name %></td>
  71. </tr>
  72. <% end %>
  73. </tbody>
  74. </table>
  75.  
  76. <br>
  77.  
  78. <%= link_to 'New User', new_user_path %>
  79.  
  80. <h1>New user</h1>
  81.  
  82. <%= render 'form' %>
  83.  
  84. <%= link_to 'Back', users_path %>
  85.  
  86. <%= form_for(@user) do |f| %>
  87. <% if @user.errors.any? %>
  88. <div id="error_explanation">
  89. <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
  90.  
  91. <ul>
  92. <% @user.errors.full_messages.each do |msg| %>
  93. <li><%= msg %></li>
  94. <% end %>
  95. </ul>
  96. </div>
  97. <% end %>
  98.  
  99. <div class="field">
  100. <%= f.label :name %><br>
  101. <%= f.text_field :name %>
  102. </div>
  103. <!-- Upload your attachments via a simple file_fields in the form -->
  104. <div class="field">
  105. <%= f.label :avatar %><br>
  106. <%= f.file_field :avatar %>
  107. </div>
  108. <div class="field">
  109. <%= f.label :resume %><br>
  110. <%= f.file_field :resume %>
  111. </div>
  112. <div class="actions">
  113. <%= f.submit %>
  114. </div>
  115. <% end %>
  116.  
  117. class UsersController < ApplicationController
  118. # GET /users
  119. def index
  120. @users = User.all
  121. end
  122.  
  123. # GET /users/new
  124. def new
  125. @user = User.new
  126. end
  127.  
  128. # POST /users
  129. def create
  130. @user = User.new(user_params)
  131.  
  132. if @user.save
  133. redirect_to action: 'index', notice: 'User was successfully created.'
  134. else
  135. render action: 'new', alert: 'User could not be created'
  136. end
  137. end
  138.  
  139. private
  140.  
  141. # Never trust parameters from the scary internet, only allow the white list through.
  142. def user_params
  143. params.require(:user).permit(:name, :avatar, :resume)
  144. end
  145. end
  146.  
  147. class User < ActiveRecord::Base
  148. #specify that the avatar is a paperclip file attachment
  149. #specify additional styles that you want to use in views or eslewhere
  150. has_attached_file :avatar, :styles => {:thumb => "100x100>"}
  151.  
  152. #specify that the resume is a paperclip file attachment
  153. has_attached_file :resume
  154.  
  155. end
  156.  
  157. Rails.application.configure do
  158. # Settings specified here will take precedence over those in config/application.rb.
  159.  
  160. # In the development environment your application's code is reloaded on
  161. # every request. This slows down response time but is perfect for development
  162. # since you don't have to restart the web server when you make code changes.
  163. config.cache_classes = false
  164.  
  165. # Do not eager load code on boot.
  166. config.eager_load = false
  167.  
  168. # Show full error reports and disable caching.
  169. config.consider_all_requests_local = true
  170. config.action_controller.perform_caching = false
  171.  
  172. # Don't care if the mailer can't send.
  173. config.action_mailer.raise_delivery_errors = false
  174.  
  175. # Print deprecation notices to the Rails logger.
  176. config.active_support.deprecation = :log
  177.  
  178. # Raise an error on page load if there are pending migrations.
  179. config.active_record.migration_error = :page_load
  180.  
  181. # Debug mode disables concatenation and preprocessing of assets.
  182. # This option may cause significant delays in view rendering with a large
  183. # number of complex assets.
  184. config.assets.debug = true
  185.  
  186. # Adds additional error checking when serving assets at runtime.
  187. # Checks for improperly declared sprockets dependencies.
  188. # Raises helpful error messages.
  189. config.assets.raise_runtime_errors = true
  190. Paperclip.options[:command_path] = 'C:Program FilesImageMagick-6.9.0-Q16'
  191. # Raises error for missing translations
  192. # config.action_view.raise_on_missing_translations = true
  193. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement