Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. class ImagesController < ApplicationController
  2. layout 'home2'
  3. #before_action :image
  4. def new
  5. @image = Image.new
  6. end
  7.  
  8. def create
  9. @image = Image.new(image_params)
  10.  
  11. if @image.save
  12. flash[:success] = "Your creation has been uploaded"
  13. #redirect_to "/showcase"
  14. else
  15. flash[:error] = "Your creation has not been uploaded"
  16. render :new
  17. end
  18. end
  19.  
  20. private
  21.  
  22. def image_params
  23. params.permit(:title, :description, :nickname, :creation)
  24. end
  25. end
  26.  
  27. <h2 align="center">Post your own creation right here !</h2>
  28. <br>
  29. <div align="center">
  30. <%= link_to 'Back', '/showcase', :class => "buttonShow" %>
  31. </div>
  32.  
  33. <%= simple_form_for @image, url: "/showcase/post", html: { multipart: true } do |f| %>
  34. <%= f.input :title, :required => true %>
  35. <%= f.input :description, :required => true %>
  36. <%= f.input :nickname, :required => true %>
  37. <div align="center">
  38. <%= f.file_field :creation, :required => true %>
  39. <%= f.button :submit, "Post !", :class => "buttonShow1" %>
  40. </div>
  41. <% end %>
  42.  
  43. Rails.application.routes.draw do
  44. resources "images", only: [:create, :new]
  45. resources "contacts", only: [:new, :create]
  46. get 'contacts/contact'
  47.  
  48. #get 'images/crea'
  49. #get 'images/post'
  50.  
  51. get 'auth/auth'
  52.  
  53. root "auth#auth"
  54. #get 'contact' => 'contacts#contact'
  55. get 'showcase/post' => 'images#create'
  56. #post 'showcase/post' => 'images#create'
  57. get 'showcase' => 'images#new'
  58. post 'showcase/post' => 'images#create'
  59. patch 'showcase/post' => 'images#new'
  60. get 'images' => 'images#new'
  61. #get 'images/new' => 'showcase'
  62. #resources "contacts", only: [:new, :create]
  63. # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  64. end
  65.  
  66. class Image < ApplicationRecord
  67.  
  68. has_attached_file :creation,
  69. :styles => {
  70. :large => "1000x1000>",
  71. :medium => "500x500>",
  72. :thumb => "300x300#"
  73. }
  74. #validates :creation, :attachment_presence => true
  75. validates_attachment_content_type :creation, content_type: /Aimage/.*z/
  76. # has_attached_file :image_filename
  77. # validates_attachment :image_filename, :presence => true
  78. #validates_attachment_file_name :image, :matches => [/pngZ/, /jpe?gZ/]
  79. #attribute :title, :presence => true
  80. # attribute :description, :validate => /A([w.%+-]+)@([w-]+.)+([w]{2,})z/i
  81. # attribute :nickname, :validate => /A([w.%+-]+)@([w-]+.)+([w]{2,})z/i
  82. end
  83.  
  84. ActiveRecord::Schema.define(version: 20160930075924) do
  85.  
  86. create_table "contacts", force: :cascade do |t|
  87. t.string "name"
  88. t.string "email"
  89. t.string "message"
  90. t.datetime "created_at", null: false
  91. t.datetime "updated_at", null: false
  92. end
  93.  
  94. create_table "images", force: :cascade do |t|
  95. t.string "title"
  96. t.string "description"
  97. t.string "nickname"
  98. t.datetime "created_at", null: false
  99. t.datetime "updated_at", null: false
  100. t.string "creation_file_name"
  101. t.string "creation_content_type"
  102. t.integer "creation_file_size"
  103. t.datetime "creation_updated_at"
  104. end
  105.  
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement