かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

[NetBeans][Ruby]Scaffoldの吐くコードを読み続ける

いや、タイトルは、従業員管理システムというにはあまりにも貧相な結果になりそうなんでやめました。
さて、前回:http://blogs.wankuma.com/kazuki/archive/2008/05/04/136273.aspx

引き続きscaffoldの吐き出すコードを見てみよう。
indexは見たので、お次はshow!

  # GET /employees/1
  # GET /employees/1.xml
  def show
    @employee = Employee.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @employee }
    end
  end

これはindexと殆ど変わらない。
ただ、urlに数字を渡すことで、そのidを持った従業員を探し出すことになってる。

んで、探し出したら後はviewに宜しく~~ってなってる。
好感持てるね。

お次はnewだ!!

  # GET /employees/new
  # GET /employees/new.xml
  def new
    @employee = Employee.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @employee }
    end
  end

これも非常にシンプルだ。
空の従業員を作って、viewによろしく!って丸投げ。これも問題ないね。

んじゃぱぱっと次!edit!

  # GET /employees/1/edit
  def edit
    @employee = Employee.find(params[:id])
  end

これは、編集画面表示するだけなのでxml無しみたい。
引数のidで従業員を検索してるだけ。respond_toとか何もしてないので、employees/edit.html.rbが表示される。

んじゃ次!createです。こいつは、今までと違う感じで、なんとifがある!!

  # POST /employees
  # POST /employees.xml
  def create
    @employee = Employee.new(params[:employee])

    respond_to do |format|
      if @employee.save
        flash[:notice] = 'Employee was successfully created.'
        format.html { redirect_to(@employee) }
        format.xml  { render :xml => @employee, :status => :created, :location => @employee }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @employee.errors, :status => :unprocessable_entity }
      end
    end
  end

パラメータから:employeesをとってきて、saveする。
保存に成功したら、redirect_to(@employee)を呼んでる。

なんじゃこれ!ということで、調べに入る。
redirect_toだから、リダイレクトするのはわかるけど…。ぐぐるのもメンドイので動かしてみる。

createアクションなので、従業員作成をしてみよう。
必要な情報を入力してCreateボタンをぽちっとな。
image

なんだろう…showメソッドあたりにリダイレクトしてるみたいだ。
ちょっと調べてみよう。

ん~手持ちのRails本では見つからない記述が結構ある。
どうも手持ちのはRails1.1ベースの本みたいだ。

Web上の別の人の記事とかを見ると、1.1 → 1.2で変わった。1.2 → 2.0でも変わった。って書いてある。

なんてこった。2世代も違う!!
失意の中ちょっと休憩。

投稿日時 : 2008年5月4日 22:44

Feedback

# Christian Louboutin shoes 2012/12/07 21:13 http://mychristianlouboutinonline.webs.com/

As soon as I discovered this web site I went on reddit to share some of the love with them.

# longchamp le pliage 2012/12/14 22:30 http://www.longchampbagoutlet.info/category/longch

Our pool could be fed through those photopages that you choose to consider worthwhile becoming system of the "Best Review Collection".

# longchamp pliage 2012/12/15 15:28 http://www.saclongchampachete.info/category/sac-lo

I guess We're not on your own having all the enjoyment in this article!

# longchamp hobo 2012/12/17 6:58 http://www.longchampfr.info/category/sac-longchamp

keep up the good operate!

# burberry coat outlet 2012/12/17 20:11 http://www.burberrycanadaoutlet.info/category/burb

this can be something i have never actually read.

# michael kors sac a main 2012/12/18 5:14 http://michael-kors-canada.webnode.fr/blog/

Very handy info. Hope to find more discussions soon!

# isabel marant sneaker 2012/12/18 19:42 http://sneakersisabelmarantsolde.monwebeden.fr

gripping avenues of comments bursting through your photos.

# soldes longchamp 2012/12/18 20:21 http://www.longchampfr.info/category/soldes-longch

I fully understand everybody should hate about them, but I do not think they take a look so poor.

# burberryukoutlets.wordpress.com 2012/12/19 13:22 http://burberryukoutlets.wordpress.com

The stars for this pool would be the comments and the pictures are generally secondary.

# tn pas cher 2013/01/09 22:29 http://www.robenuk.eu/

Happen to be last a long time whenever just about every single coworker believes that they have a small favourable position during the other sorts of.
tn pas cher http://www.robenuk.eu/

# destockchine 2013/03/02 18:08 http://www.c55.fr/

At affluence our favorite family already know individuals; found in hard knocks children our favorite family. destockchine http://www.c55.fr/

# casquette supreme 2013/03/02 18:08 http://www.b66.fr/

Friendships keep going as every last relative says he's a small brilliance for several many other. casquette supreme http://www.b66.fr/

# www.tt6262.com 2013/03/04 5:04 http://tt6262.com/

A very crony most likely are not a buddy, however , a buddy will almost allways be some crony. www.tt6262.com http://tt6262.com/

# Tous les prix 2013/03/05 0:43 http://www.g33.fr/

Pleasure rrs really a essence you may not serve about others without having remember , getting a small number comes about oneself. Tous les prix http://www.g33.fr/

# K88.fr 2013/03/05 0:43 http://www.k88.fr/

At which may perhaps be marital whilst not fancy, it will be fancy whilst not marital. K88.fr http://www.k88.fr/

# uknow 2013/03/05 0:46 http://www.f77.fr/

Please don't make friends that snug to be with. To understand who will force a single pry your business up. uknow http://www.f77.fr/

# casquette supreme 2013/03/17 7:00 http://www.b44.fr/

Get into‘big t use up your time and energy on the man or woman/feminine,who also isn‘big t happy to use up his or her's instance giving you. casquette supreme http://www.b44.fr/

# destockchine 2013/03/24 0:41 http://d77.fr/

No need to make friends who're luxurious to get along with. Socialize which will pressure one lever tumbler all by yourself on. destockchine http://d77.fr/

# destockchine 2013/03/25 2:32 http://c99.fr/

All of the least beneficial technique girl a person can be placed right adjacent to these animals being aware you possibly can‘d you can keep them. destockchine http://c99.fr/

# usine23 2013/03/25 5:11 http://e55.fr/

A very honestly may not be someone, yet somehow someone will always be a suitable honestly. usine23 http://e55.fr/

# pick your shoes 2013/04/03 7:33 http://nikejordanretro7ok.com/

You should not it's the perfect time which might be cosy to get along with. Make friends who will power you to pry yourself together. pick your shoes http://nikejordanretro7ok.com/

# 3suisses 2013/04/07 1:21 http://ruenee.com/

The place may perhaps be nuptials without the need of affection, it'll be affection without the need of nuptials. 3suisses http://ruenee.com/

# coachoutletcoupon88.com 2013/04/07 14:47 http://www.coachoutletcoupon88.com/

Some sibling very likely are not friends, although friends are invariably an important sibling. coachoutletcoupon88.com http://www.coachoutletcoupon88.com/

# Casquette New Era 2013/04/07 17:20 http://www.ruesee.com/

Absolutely adore will be the primarily rational and thus positive solution most typically associated with our living. Casquette New Era http://www.ruesee.com/

# Laredoute 2013/04/07 19:02 http://ruezee.com/

Take pleasure in is without a doubt weak in entry into the world, it grows up more powerful as they age whether it's the right way provided. Laredoute http://ruezee.com/

タイトル
名前
Url
コメント