Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ImagesController < ApplicationController
- layout 'home2'
- #before_action :image
- def new
- @image = Image.new
- end
- def create
- @image = Image.new(image_params)
- if @image.save
- flash[:success] = "Your creation has been uploaded"
- #redirect_to "/showcase"
- else
- flash[:error] = "Your creation has not been uploaded"
- render :new
- end
- end
- private
- def image_params
- params.permit(:title, :description, :nickname, :creation)
- end
- end
- <h2 align="center">Post your own creation right here !</h2>
- <br>
- <div align="center">
- <%= link_to 'Back', '/showcase', :class => "buttonShow" %>
- </div>
- <%= simple_form_for @image, url: "/showcase/post", html: { multipart: true } do |f| %>
- <%= f.input :title, :required => true %>
- <%= f.input :description, :required => true %>
- <%= f.input :nickname, :required => true %>
- <div align="center">
- <%= f.file_field :creation, :required => true %>
- <%= f.button :submit, "Post !", :class => "buttonShow1" %>
- </div>
- <% end %>
- Rails.application.routes.draw do
- resources "images", only: [:create, :new]
- resources "contacts", only: [:new, :create]
- get 'contacts/contact'
- #get 'images/crea'
- #get 'images/post'
- get 'auth/auth'
- root "auth#auth"
- #get 'contact' => 'contacts#contact'
- get 'showcase/post' => 'images#create'
- #post 'showcase/post' => 'images#create'
- get 'showcase' => 'images#new'
- post 'showcase/post' => 'images#create'
- patch 'showcase/post' => 'images#new'
- get 'images' => 'images#new'
- #get 'images/new' => 'showcase'
- #resources "contacts", only: [:new, :create]
- # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
- end
- class Image < ApplicationRecord
- has_attached_file :creation,
- :styles => {
- :large => "1000x1000>",
- :medium => "500x500>",
- :thumb => "300x300#"
- }
- #validates :creation, :attachment_presence => true
- validates_attachment_content_type :creation, content_type: /Aimage/.*z/
- # has_attached_file :image_filename
- # validates_attachment :image_filename, :presence => true
- #validates_attachment_file_name :image, :matches => [/pngZ/, /jpe?gZ/]
- #attribute :title, :presence => true
- # attribute :description, :validate => /A([w.%+-]+)@([w-]+.)+([w]{2,})z/i
- # attribute :nickname, :validate => /A([w.%+-]+)@([w-]+.)+([w]{2,})z/i
- end
- ActiveRecord::Schema.define(version: 20160930075924) do
- create_table "contacts", force: :cascade do |t|
- t.string "name"
- t.string "email"
- t.string "message"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- end
- create_table "images", force: :cascade do |t|
- t.string "title"
- t.string "description"
- t.string "nickname"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "creation_file_name"
- t.string "creation_content_type"
- t.integer "creation_file_size"
- t.datetime "creation_updated_at"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement