運動記録アプリを開発中のこと

編集した際画像のように全て同じ様になってしまった。

原因をbinding.pryで調べた結果

global-container
実数 N、自然数 M が入力されます。N を丸めて小数第 M 位まで出力してください。
また、N の小数部が小数第 M 位に満たない場合は 0 で埋めて出力してください。
なお、小数第 M 位が 5 になることはありません。
自然な丸め処理を行って出力すると正解になります。
入力例 0.813 4 出力例4 0.8130
n,m = gets.split(' ').map(&:to_f)
# 小数点以下の桁数を指定しています
printf("%.#{m.to_i}f", n)
自然数 Q が与えられます。Q 回以下の問題に答えてください。
実数 N、自然数 M が入力されます。N を丸めて小数第 M 位まで出力してください。また、N の小数部が小数第 M 位に満たない場合は 0 で埋めて出力してください。
なお、小数第 M 位が 5 になることはありません。
自然な丸め処理を行って出力すると正解になります。
4 0.813 1 0.813 2 0.813 3 0.813 4
0.8 0.81 0.813 0.8130
自然数 N が与えられます。1 ≦ i ≦ N の各 i について、i 行目には以下の数列を出力してください。* 1 以上 i 以下の数値をすべて、半角スペース区切りで出力してください
4
出力例1
1 1 2 1 2 3 1 2 3 4
n = gets.to_i
a = *(1..n)
1..n.times do |i|
puts a.take(a[i]).join(' ')
end
自然数NとN個の要素の数列Mが与えられます。
1 ≦ i ≦ N の各 i について、i 行目には以下の数列を出力してください。
1 以上 M_i 以下のすべての自然数を昇順、半角スペース区切りで出力してください。
4 2 4 3 1
1 2 1 2 3 4 1 2 3 1
1 1
1
n = gets.to_i
m = gets.split(' ').map(&:to_i)
n.times do |i|
# ここで先に1,2,3,とやってから
(m[i]-1).times { |j| print "#{j +1 } "}
# 最後にmの配列を足す
puts m[i]
end
Showing /lifehack/app/views/layouts/_head.html.erb where line #8 raised:
SyntaxError: [stdin]:5:19: reserved word ‘function’
Trace of template inclusion: app/views/layouts/application.html.erb
初めてみたエラーだったので記録
JQueryのスクリプトをパーシャルとしてリファクタリングしようとした。
javascripts/task.coffeeに間違えて以下(JQueryのスクリプト)を記述したら生じた。
<script>
$("span").click(function () {
$("h3").toggle("slow");
});
</script>
javascripts/task.coffeeの↑の記述を削除する。
views/shared/_script.html.erbにスクリプトを記述して
<%= render 'shared/script' %>
で使いました。

初めて見たエラーだったので対処法を記しておきます。
chart.jsでグラフを作るために記事を参考に試したところエラーが発生した。
window.draw_graph = ->
ctx = document.getElementById("myChart").getContext('2d')
barNum = 6
labels = new Array(barNum)
bgColors = new Array(barNum)
bdColors = new Array(barNum)
for i in [0...barNum]
labels[i] = 'data' + i
bgColors[i] = 'rgba(75, 192, 192, 0.2)'
bdColors[i] = 'rgba(75, 192, 192, 1)'
myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels
datasets: [{
label: '# of Votes',
data: gon.data,
backgroundColor: bgColors,
borderColor: bdColors,
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
})
インデントのズレなど構文が間違っているとなるようです。
Rubymineの自動フォーマット(⌥+⌘+Lキー)でインデント修正して解決しました。
window.draw_graph = ->
ctx = document.getElementById("myChart").getContext('2d')
barNum = 6
labels = new Array(barNum)
bgColors = new Array(barNum)
bdColors = new Array(barNum)
for i in [0...barNum]
labels[i] = 'data' + i
bgColors[i] = 'rgba(75, 192, 192, 0.2)'
bdColors[i] = 'rgba(75, 192, 192, 1)'
myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels
datasets: [{
label: '# of Votes',
data: gon.data,
backgroundColor: bgColors,
borderColor: bdColors,
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
})

よくあるエラーらしいので、遭遇しても落ち着いて対処しよう
28 29 30 31 32 33 |
def show
@macs = @user.macs.page(params[:page]).per(8)
end
def update
|
ハマってしまったので、同じことを繰り返さないために。
<span class="btn-sticky">すべての更新、作成日時を表示,非表示</span>
<% if @user.macs.any? %>
<% @user.macs.each do |mac| %>
<section class="panel">
<div class="panel-left">
<h2>目標:<%= mac.measurable %></h2>
<h2>ゴールまでのプロセス<br><%= mac.actionable %></h2>
<h2>目標達成が価値観に基づいているか?<br><%= mac.competent %></h2>
<li><h3>更新日時:<%= mac.updated_at.to_s(:datetime_jp) %></h3>
<h3>作成日時:<%= mac.created_at.to_s(:datetime_jp) %></h3></li>
</ul>
</div>
<div class="panel-right">
<%= link_to(content_tag(:i, '', class: "fas fa-trash-alt fa-3x faa-horizontal animated-hover fa-pull-right", style: "color: rgb(80,80,80);"), mac_path(mac.id), method: :delete, data: {confirm: "本当に削除しますか?"}) %>
<%= link_to(content_tag(:i, '', class: "fas fa-edit fa-3x faa-vertical animated-hover fa-pull-right", style: "color: rgb(80,80,80);"), edit_mac_path(mac.id)) %>
</section>
<% end %>
<% end %>
<%= render 'shared/script' %>
user_idに紐付いたmacモデルのもの(:measurable, :actionable, :competent)を繰り返しで表示させたかった。
def show @macs = @user.macs.page(params[:page]).per(8) end
@userをmacs_controller.rbに定義していなかったためnilになった。
機能がほぼ同じだったので他のコントローラーからコピペしたせいで
リファクタリングでprivate にあった@user = User.find(params[:id])
を見落としていたため。
***_controller.rb
def show @user = User.find(params[:id]) @macs = @user.macs.page(params[:page]).per(8) end
@user = User.find(params[:id])
この記事は、プログラミング問題などでよく見られる、標準入力から値を受け取る方法をまとめたものです。
使用する言語はRubyです。
Ruby
string = gets
p string
"Ruby"
Ruby PHP Python
strings = gets.split
p strings
["Ruby", "PHP", "Python"]
splitを使用することで、3つの要素をそれぞれ別のものとして配列に格納しています。
※splitの使い方
split(‘ ‘)としている記事などもありますが、
半角スペース刻みの入力値の場合は引数(‘ ‘)を指定しなくても問題ありません。
つまりsplit(‘ ‘) ≒ split (※半角スペース刻みの入力値のときのみです)
Ruby
PHP
Python
strings = readlines.map(&:chomp)
#またはこちら(パフォーマンス的に推奨)
strings = readlines(chomp: true)
p strings
["Ruby", "PHP", "Python"]
Ruby PHP Python
Java C# C++
strings = readlines.map{ |i| i.split.map(&:chomp)}
# またはこちら(推奨)
strings = readlines.map(&:split)
p strings
出力結果
[["Ruby", "PHP", "Python"], ["Java", "C#", "C++"]]
Ruby PHP Python
Java C# C++
123
number = gets.to_i
p number
123
1 2 3
numbers = gets.split.map(&:to_i)
p numbers
[1, 2, 3]
1
2
3
numbers = readlines.map(&:to_i)
p numbers
[1, 2, 3]
1 2 3
4 5 6
numbers = readlines.map{ |i| i.split.map(&:to_i) }
p numbers
[[1, 2, 3], [4, 5, 6]]
574 575 576 577 578 579 |
# Raises <tt>ActiveRecord::PendingMigrationError</tt> error if any migrations are pending.
def check_pending!(connection = Base.connection)
raise ActiveRecord::PendingMigrationError if ActiveRecord::Migrator.needs_migration?(connection)
end
def load_schema_if_pending!
|
docker-compose exec web bundle exec rake db:migrate