Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
41 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ | ||
$ -> | ||
$('#memos') | ||
.on 'click', '.edit, .cancel', (event) -> | ||
# 表示を切り替え | ||
toggleEditor $(this).closest('.memo') | ||
|
||
# 表示モードと編集モードを切り替える。 | ||
toggleEditor = ($container) -> | ||
# 表示、非表示を切り替え | ||
$container.find('.viewer, .editor').toggle() | ||
|
||
# 編集モードなら、値を戻す | ||
$bodyField = $container.find('.editor .body') | ||
if $bodyField.is(':visible') | ||
$bodyField | ||
.val($container.find('.viewer .body').text()) | ||
.select() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// Place all the styles related to the memos controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ | ||
.memo { | ||
border: solid 1px #eee; | ||
margin: 10px; | ||
padding: 10px; | ||
} | ||
.memo .editor { | ||
display: none; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,4 @@ | ||
<%= form_for(@memo) do |f| %> | ||
<% if @memo.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@memo.errors.count, "error") %> prohibited this memo from being saved:</h2> | ||
|
||
<ul> | ||
<% @memo.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :body %><br /> | ||
<%= f.text_field :body %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<%= form_for memo do |f| %> | ||
<%= f.text_field :body, id: nil, class: 'body' %> | ||
<%= f.submit 'Update' %> | ||
<% end %> |
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