Created
July 8, 2018 08:16
-
-
Save yu-smc/67a1a233efb79be30be9ebd657cfbe40 to your computer and use it in GitHub Desktop.
dohamari
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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_0 | |
= image.file_field :content | |
= image.hidden_field :status, value: "main" | |
= image.hidden_field :order, value: 0 | |
.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(id='selected_image_#{i+1}') | |
= image.file_field :content | |
= image.hidden_field :status, value: "sub" | |
= image.hidden_field :order, value: i + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
end | |
def update | |
if @prototype.update(prototype_params) | |
# binding.pry | |
redirect_to prototype_path(@prototype), notice: 'New prototype was successfully updated' | |
else | |
redirect_to ({ action: :new }), alert: 'New prototype was unsuccessfully updated' | |
end | |
end | |
def destroy | |
prototype = Prototype.find(params[:id]) | |
prototype.destroy if prototype.user_id == current_user.id | |
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, :order] | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment