Skip to content

Instantly share code, notes, and snippets.

@yu-smc
yu-smc / ログ
Created July 11, 2018 02:59
EC2環境下でrails assets:precompileがうまくいかない
> Successfully installed Yarn 1.7.0! Please open another terminal where the `yarn` command will now be available.
[ec2-user@ip-172-31-32-152 chat-space]$ rails assets:precompile
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
[ec2-user@ip-172-31-32-152 chat-space]$ source ~/.bashrc
[ec2-user@ip-172-31-32-152 chat-space]$ yarn -v
1.7.0
[ec2-user@ip-172-31-32-152 chat-space]$ rails assets:precompile
yarn install v1.7.0
@yu-smc
yu-smc / edit.html.haml
Last active July 8, 2018 15:02
編集機能について現状わかっていること
.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
@yu-smc
yu-smc / preview_image.js
Created July 8, 2018 14:06
プレビュー機能の説明
//略
$(function (){
//type属性がfileのinputタグに変化があった(=ファイルが選択された)ら発火
$('input[type="file"]').on('change',function previewFile(e) {
//変更があった要素の1個前のimg要素をpreviewとする
var preview = $(this).prev('img')[0]
//のちのち消します
console.log($(this).prev('img')[0]);
//この2行は定型の書き方で、Filereaderを使って選択されたファイルを取得
var file = e.target.files[0];
@yu-smc
yu-smc / ログ
Created July 8, 2018 08:19
どはまり
[2] pry(#<PrototypesController>)> @prototype.captured_images
CapturedImage Load (0.6ms) SELECT `captured_images`.* FROM `captured_images` WHERE `captured_images`.`prototype_id` = 5
=> [#<CapturedImage:0x007ffaa7ab15b8
id: 8,
content: "b2_02.jpg",
status: 0,
prototype_id: 5,
order: 0>,
#<CapturedImage:0x007ffaa7ab13d8
id: 9,
.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
@yu-smc
yu-smc / css.stylesheet.css
Last active July 5, 2018 03:24
複数項目の詳細表示 / 非表示を、JQuery5行で実装する ref: https://qiita.com/yu-smc/items/9bbd57f1e842eda20a18
.pulldown {
width: 300px;
margin: 0 0 10px 20px;
}
.pulldown-head {
background-color: lightgreen;
height: 40px;
}
$(document).on('turbolinks:load', function() {
$(function (){
$('#prototype_captured_images_attributes_0_content').on('change',function previewFile(e) {
var preview = $("#selected_image")
var file = e.target.files[0];
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
$("#selected_image").attr("src", preview.src);
.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
@yu-smc
yu-smc / gist:bc1dd2231d3609fb85411155e4d6bd95
Created June 30, 2018 05:49
editアクションの初回に画像が見つからずリロード時に見つけてくれたログ
Started GET "/prototypes/1/edit" for ::1 at 2018-06-30 14:43:15 +0900
Processing by PrototypesController#edit as HTML
Parameters: {"id"=>"1"}
Prototype Load (6.5ms) SELECT `prototypes`.* FROM `prototypes` WHERE `prototypes`.`id` = 1 LIMIT 1
CapturedImage Load (0.3ms) SELECT `captured_images`.* FROM `captured_images` WHERE `captured_images`.`prototype_id` = 1 AND `captured_images`.`id` = 1 LIMIT 1
User Load (0.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
CapturedImage Load (0.3ms) SELECT `captured_images`.* FROM `captured_images` WHERE `captured_images`.`prototype_id` = 1
Rendered prototypes/edit.html.haml within layouts/application (9.3ms)
Rendered shared/_header.html.haml (1.5ms)
Rendered shared/_messages.html.haml (0.1ms)
@yu-smc
yu-smc / file0.js
Last active May 19, 2018 10:56
JavaScriptで取得した日付(年月日)を英語表記してみる (1行ごとに解説) ref: https://qiita.com/yu-smc/items/8bdde9ff6729ce848c09
function get_english_date() {
const month_english_list = ['Jan.','Feb.','Mar.','Apr.','May','June','July','Aug.','Sept.','Oct.','Nov.','Dec.']
//月の英語表記を配列に定義。省略形は不規則で、①Mayは3文字だからカンマはいらない、②June, Julyは4文字のまま、③9月は4文字でSept. 初めて知った。
var date = new Date()
//Dateオブジェクトで日付を取得(引数を持たせなければ現在時刻を取得する)
var month = date.getMonth()
//dateから月を取り出してmonthに代入
var month_english = month_english_list[month]