2013年7月20日土曜日

今週も三葛行ってきました。

三葛はいいね。以前の筋肉に戻っていないので、四葛は難しい。

山頂の店がなくなったので、最近は蕎原に降りて蕎原山荘でいつもエネルギー補給をしています。今日は卵掛けご飯とパンでした。卵のからは緑色をしていたな。。
最後はロイヤルの氷です。
卵の空が緑色です。わかりますか?
結構美味しかった。

三葛前のエネルギー補給(あんぱんとあん揚げパン)

最後に和歌山側に降りてきてからロイヤルの氷

2013年7月15日月曜日

rails ネストサンプル


routes.rb
  resources :posts do
    resources :comments
  end

posts_controller.rb
class PostsController < ApplicationController
  # GET /posts
  # GET /posts.json
  def index
    @posts = Post.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @posts }
    end
  end

  # GET /posts/1
  # GET /posts/1.json
  def show
    @post = Post.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @post }
    end
  end

  # GET /posts/new
  # GET /posts/new.json
  def new
    @post = Post.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @post }
    end
  end

  # GET /posts/1/edit
  def edit
    @post = Post.find(params[:id])
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = Post.new(params[:post])

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render json: @post, status: :created, location: @post }
      else
        format.html { render action: "new" }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /posts/1
  # PUT /posts/1.json
  def update
    @post = Post.find(params[:id])

    respond_to do |format|
      if @post.update_attributes(params[:post])
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post = Post.find(params[:id])
    @post.destroy

    respond_to do |format|
      format.html { redirect_to posts_url }
      format.json { head :no_content }
    end
  end
end

posts _form.html.erb
<%= form_for(@post) do |f| %>
  <% if @post.errors.any? %>
    

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

    <% @post.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
<% end %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :body %>
<%= f.text_area :body %>
<%= f.submit %>
<% end %>
posts edit.html.erb

Editing post

<%= render 'form' %> <%= link_to 'Show', @post %> | <%= link_to 'Back', posts_path %>
posts index.html.erb

Listing posts

<% @posts.each do |post| %> <% end %>
Title Body
<%= post.title %> <%= post.body %> <%= link_to 'Show', post %> <%= link_to 'Edit', edit_post_path(post) %> <%= link_to 'Edit', edit_post_url(post) %> <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to 'New Post', new_post_path %>
posts show.html.erb

New post

<%= render 'form' %> <%= link_to 'Back', posts_path %>
<%= notice %>
Title: <%= @post.title %>
Body: <%= @post.body %>
<%= link_to 'Comments',post_comments_path(@post) %> <%= link_to 'Edit', edit_post_path(@post) %> | <%= link_to 'Back', posts_path %>
comments_controller.rb
class CommentsController < ApplicationController
  # GET /comments
  # GET /comments.json
  def index
    @post = Post.find(params[:post_id])

    @comments = @post.comments

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @comments }
    end
  end

  # GET /comments/1
  # GET /comments/1.json
  def show
    p params
    @post = Post.find(params[:post_id])
    @comment = Comment.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @comment }
    end
  end

  # GET /comments/new
  # GET /comments/new.json
  def new
    @post = Post.find(params[:post_id])
    @comment = @post.comments.new


    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @comment }
    end
  end

  # GET /comments/1/edit
  def edit
    @comment = Comment.find(params[:id])
  end

  # POST /comments
  # POST /comments.json
  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.new(params[:comment])

    respond_to do |format|
      if @comment.save
        format.html { redirect_to [@post,@comment], notice: 'Comment was successfully created.' }
        format.json { render json: @comment, status: :created, location: @comment }
      else
        format.html { render action: "new" }
        format.json { render json: @comment.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /comments/1
  # PUT /comments/1.json
  def update
    @post = Post.find(params[:post_id])
    @comment = Comment.find(params[:id])

    respond_to do |format|
      if @comment.update_attributes(params[:comment])
        format.html { redirect_to [@post,@comment], notice: 'Comment was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @comment.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /comments/1
  # DELETE /comments/1.json
  def destroy
    @post = Post.find(params[:post_id])
    @comment = Comment.find(params[:id])
    @comment.destroy

    respond_to do |format|
      format.html { redirect_to post_comments_url(@post) }
      format.json { head :no_content }
    end
  end
end
comments _form.html.erb
<%= form_for([@post,@comment]) do |f| %>
  <% if @comment.errors.any? %>
    

<%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:

    <% @comment.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
<% end %>
<%#= f.label :post %>
<%#= f.text_field :post %>
<%= f.label :body %>
<%= f.text_area :body %>
<%= f.submit %>
<% end %>
comments edit.html.erb

Editing comment

<%= render 'form' %> <%= link_to 'Show', [@post,@comment] %> | <%= link_to 'Back', post_comment_path %>
comments index.html.erb

Listing comments

<% @comments.each do |comment| %> <% end %>
Post Body
<%= comment.post.title %> <%= comment.body %> <%= link_to 'Show', post_comment_path(@post,comment) %> <%= link_to 'Edit', edit_post_comment_path(@post,comment) %> <%= link_to 'Destroy', post_comment_path(@post, comment), method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to 'back' ,post_path(@post) %> <%= link_to 'New Comment', new_post_comment_path %>
comments new.html.erb

New comment

<%= render 'form' %> <%= link_to 'Back', post_comments_path(@post.id) %>
<%= notice %>
Post: <%= @comment.post %>
Body: <%= @comment.body %>
<%= link_to 'Edit', edit_post_comment_path %> | <%= link_to 'Back', post_comments_path %>
models posts.rb
class Post < ActiveRecord::Base
  attr_accessible :body, :title
  has_many :comments

end
models post.rb
class Comment < ActiveRecord::Base
  belongs_to :post
  attr_accessible :body
end

チェーンの交換時期になっている

今日自転車を洗って、チェーンの伸びを測定してみると、既に0.75パーセントを超えて1パーセントの伸びになっていました。来週あたりに「町の自転車修理屋さん」でチェーンの交換をしよう。やはり角度が急な山を登り始めると、チェーンの伸びが速くなったような気がします。

2013年7月14日日曜日

rails4を少しさわってました

セキュリティ関係が強化されて、情報に関してグラフィカルになっているような気がします。
ルート表示はこんな感じになっています(localhost:3000/rails)
エラー表示はこんな感じ(以前に比べれば格段に良くなっています)
エラー表示に関しては別gemの方が使い勝手が良いです。
group :development do
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'meta_request'
end
赤枠を追加したところで変数の値の確認も出来ます。

2013年7月13日土曜日

ガリガリ君 当たりました

会社の昼休みに何気なくガリガリ君を買って、食べてみると。なんと当たりました。ここ三年ほど夏場は自転車に乗る毎に1〜3本食べているの全く当たりませんでしたが、ついに当たりました。多分トータルで40本以上食べています。
感動です。昔はもっと当たる確率が高かったような気がします。

久しぶりに三葛してきました

三回葛城山に登るのを久しぶりにしました。筋力が落ちてタイムもダウン。昼食に蕎原山荘に初めて行きましたが、良いところです。今回は大盛りカレー。今度は卵掛けごはんに挑戦しよう。
まだ凍結注意の看板が。。

蕎原山荘での昼食の後の揚げバン(二葛城直前のエネルギー補給)

あんぱんと揚げバン(三葛城直前のエネルギー補給)

三葛城ではさすがに疲れてここで小休憩

これが有名な岸和田ツーリングクラブの葛城山山頂の記帳です。
三葛の記録はのこしました。

暑いと思ったら、4時前の葛城山山頂の気温が33度

2013年7月7日日曜日

高野龍神スカイラインに行ってきました

護摩山スカイタワーまで行くつもりでしたが、山の上でもあまりの暑さに高野山とスカイタワーの真ん中ぐらいで引き返してきました。
山のうえでこれほど暑いって珍しい。
高野山に二軒目のコンビニ。今度はメインの通りに有ります。(来週の火曜日にオープンみてたい)

一本目のガリガリ君



このキャラクターの名前を初めてしりました。『こうやくん』です

昼はいつもの『とんかつ定』注文したのはトンカツ定食。
おいしい。

高野山でも25度有りました。山の下は30度以上か?

二本目のガリガリ君