Skip to content

Instantly share code, notes, and snippets.

@yu-smc
Created June 30, 2018 05:51
Show Gist options
  • Save yu-smc/30b2f0e74379a97053e8abc372ecfa53 to your computer and use it in GitHub Desktop.
Save yu-smc/30b2f0e74379a97053e8abc372ecfa53 to your computer and use it in GitHub Desktop.
.container.proto-new
= form_for @prototype do |f|
= f.hidden_field :user_id, value: current_user.id
.col-md-8.col-md-offset-2
%header.row.user-nav.row
.col-md-12
%h4 Title
.proto-new-title
= f.text_field :title, required: true, autofocus: true, placeholder: "Input Title"
.row
.col-md-12
%h4 Main Thumbnail
.cover-image-upload#main_image_uploader
= f.fields_for :captured_images do |image|
%img#selected_image
= image.file_field :content
= image.hidden_field :status, value: "main"
.col-md-12
%h4 Sub Thumbnails
%ul.proto-sub-list.list-group
- 3.times do |i|
%li.list-group-item.col-md-4
.image-upload
= f.fields_for :captured_images do |image|
%img
= image.file_field :content
= image.hidden_field :status, value: "sub"
.row.proto-description
.col-md-12
%h4 Catch Copy
= f.text_field :catch_copy, require: true, placeholder: "Input Catch Copy"
.col-md-12
%h4 Concept
= f.text_area :concept, require: true, placeholder: "Input Concept"
.row.text-center.proto-btn
= f.submit "SAVE", id: "button", class: "btn btn-lg btn-primary btn-block"
class PrototypesController < ApplicationController
before_action :set_prototype, only: [:show, :edit, :update]
def index
@prototypes = Prototype.all.page(params[:page]).per(10)
end
def new
@prototype = Prototype.new
@prototype.captured_images.new
end
def create
@prototype = Prototype.new(prototype_params)
if @prototype.save
redirect_to :root, notice: 'New prototype was successfully created'
else
redirect_to ({ action: :new }), alert: 'New prototype was unsuccessfully created'
end
end
def show
end
def edit
@prototype.captured_images.find(params[:id])
end
def update
if @prototype.update(prototype_params)
redirect_to :root, notice: 'New prototype was successfully updated'
else
redirect_to ({ action: :new }), alert: 'New prototype was unsuccessfully updated'
end
end
private
def set_prototype
@prototype = Prototype.find(params[:id])
end
def prototype_params
params.require(:prototype).permit(
:title,
:catch_copy,
:concept,
:user_id,
captured_images_attributes: [:id, :content, :status]
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment