8 4 end 5 6 private def message 7 'Hello' 8 end 9 end g = Greeting.new 12 g.hello $ ruby lib/lessons/greeting.rb Hello Ruby public method protec

Similar documents
6 (1) app.html.eex 28 lib/nano_planner_web/templates/layout/app.html.eex 27 <footer> Oiax Inc <%= this_year() %> Oiax Inc. 29 </footer>

16 (2) 23 - <div class="col-12 col-md-4"> </div> 23 + <div class="col-12 col-md-4 bg-info text-white text-md-right"> </div> HTML bg-info #17

10 (1) s 10.2 rails c Rails 7 > item = PlanItem.new => #<PlanItem id nil, name nil,...> > item.name = "" => "" > item.valid? => true valid? true false

8 7 + <div class='col-12 col-md-8'> 8 <%= item.description %> 9 </div> 10 </div> 11 <% end %> 12 </div> class container container-fluid PicoPlan

15 Phoenix HTML 15.1 ModestGreeter RAVT web/router.ex web/router.ex : 12 scope "/", ModestGreeter do 13 pipe_through :browser get "/", TopCont

9 Bootstrap Font Awesome 52 + gem 'bootstrap', '4.0.0.alpha6' 53 + gem 'tether-rails' Gem bootstrap tether-rails Bootstrap JavaScript Tether Ctrl-C Ra

11 Bootstrap Font Awesome $ cd ~/projects/modest_greeter $ npm install --save jquery popper.js tether --save package.json depen

16 NanoPlanner name PlanItem.changeset/2 > validate_required([:name]) name :name Ecto.Changeset validate_required/3 Ecto.Changeset "validate_"

ii

Microsoft Word - Live Meeting Help.docx

WDI-Slides-14.pptx

3 top#index 1 web router.ex web/router.ex 12 scope "/", NanoPlanner do 13 pipe_through browser get "/", TopController, index 16 end URL / to

FS_handbook.indd

■サイトを定義する

9 rbenv rbenv ruby 9.1 rbenv rbenv rbenv ruby ruby-build ruby 9.2 rbenv macos.bash_profile ~/.bash_profile ~/.bash_profile.bak $ touch ~/.bash_profile

Kyosuke MOROHASHI

113_0405.indd

データを TreeView コントロールで表示 VisualStudio2017 の Web サイトプロジェクトで bootstrap, 及び script フォルダの js ファイルが使用できるマスターページを親とする TestTreeView.aspx ページを作成します 下記の html コー

WDA-Slides-06.pptx

1

WDA-Slides-07.pptx

key

vuejs_meetup.key

利用者

ソフトウェアエンジニアリング - バグ #7

WDI-Slides-11.pptx

橡点検記録(集約).PDF

Chapter 1 イントロダクション p.21 第 2 段落 p.42 第 2 段落の 1 行目 p.45 Hint 美しいコードが書けるから Rails を選んだ美しいコードが書けるから Ruby を選んだフォルダ main app controllers を開いてみましょう フォルダ app

haskell.gby

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

untitled

WDA-Slides-12.pptx

CSSNiteLP51-s7-kubo.key

ii II Web Web HTML CSS PHP MySQL Web Web CSS JavaScript Web SQL Web

untitled

『赤すぐ』『妊すぐ』<出産・育児トレンド調査2003>

2 Rails pico planner camel case camel pico planner _ pico_planner snake case snake - chain case chain pico planner pico-planner CSS id class 2.3 Rails

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

JavaScript の使い方

flex06_01_28

CSR報告書

Ruby 2.3 のてざわり新機能と使いどころ Kunihiko Ito ESM 富山合同勉強会

untitled


FA0072 FA0028

浦安ライオンズクラブ81獅子吼.indd

<348C8E8D862E696E6464>

4 $ alias elixirc="elixirc --ignore-module-conflict" warning redefining module User (current version loaded from Elixir.User.beam) user.ex1 User alias

untitled


Sinatra と MongoDB 今回は Sinatra で MongoDB の操作を体験してみます 進捗に合わせて ドライバから Ruby で使える便利な ORM の紹介をします

PostgreSQLによる データベースサーバ構築技法


WPD2009_Plone3_theme-2.key

43-03‘o’ì’¹‘®”q37†`51†i„¤‰ƒ…m†[…g†j.pwd

Wiki Wiki Wiki...

…l…b…g…‘†[…N…v…“…O…›…~…fi…OfiÁŸ_

Java (5) 1 Lesson 3: x 2 +4x +5 f(x) =x 2 +4x +5 x f(10) x Java , 3.0,..., 10.0, 1.0, 2.0,... flow rate (m**3/s) "flow

Microsoft PowerPoint - ruby_instruction.ppt

CSSNite-LP54-kubo-ito.key

( ( ( )

_IMv2.key


基礎 Ruby on Rails 初版第 1 刷正誤表 基礎 Ruby on Rails ( 黒田努 佐藤和人著 株式会社オイアクス監修 インプレスジャパン刊 ) 初版第 1 刷 の正誤表です 特に重要な項目には 印を付しました また 付録 CD-ROM において chapter3 ディレクトリの中

VB.NETコーディング標準


ohp1.dvi

progate-team

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

要素にフォーカスが当たったときは 例えば以下のように記述する input:focus{} 疑似要素 p:first-lin{ } 一行目だけ p:first-letter{} 最初の文字だけ要素の前や後に付け加えるには 以下のように記述する p:before{content:" 記号や文字 ";}

netcdf

平成20年度内部評価実施結果報告書《本編》

untitled

技術流出防止指針公表用.PDF


0ミ0、0・タ

2016年度OSS【Open技術分科会】第3回OSS勉強会

portfolioweb用

tkk0408nari

外為オンライン FX 取引 操作説明書

1 2

untitled

INDEX

INDEX


1002goody_bk_作業用

PowerPoint Presentation

地域と文化資産


-2-


ONPRESS190

920P-1



広報しもつけp01ol


本文(B5×40)0614三校責了.indd


_勉強会_丸山さつき_v3

Transcription:

8 Rails 8.1 PicoPlanner Ruby lib lessons $ mkdir -p lib/lessons lib/lessons greeting.rb lib/lessons/greeting.rb (New) 1 class Greeting 2 def hello 3 puts message 87

8 4 end 5 6 private def message 7 'Hello' 8 end 9 end 10 11 g = Greeting.new 12 g.hello $ ruby lib/lessons/greeting.rb Hello Ruby public method protected method private method def visibility C Greeting hello message greeting.rb lib/lessons/greeting.rb 11 g = Greeting.new 12 g.hello 13 + puts g.message 88

8.1 puts g.message lib/lessons/greeting.rb13in `<main>' private method `message' called > for #<Greeting0x0055633f12ef10> (NoMethodError) greeting.rb lib/lessons/greeting.rb 1 class Greeting 2 def hello 3 - puts message 3 + puts self.message 4 end lib/lessons/greeting.rb3in `hello' private method `message' called for > #<Greeting0x0056311cd0d8a8> (NoMethodError) from lib/lessons/greeting.rb12in `<main>' class K private def foo 'foo' end def bar 'Bar' end end 2 private private 89

8 K foo bar Rails def private Ruby 2.1 2013 12 Ruby 2.1 private K foo class K def foo 'foo' end private foo end Ruby 2.1 def end def private 8.2 plan_item_params plan_items create update app/controllers/plan_items_controller.rb 21 def create 22 PlanItem.create!( 23 params[plan_item].permit(name, description, starts_at, ends_at) 90

8.2 plan_item_params 24 ) 25 26 redirect_to plan_items 27 end 28 29 def update 30 plan_item = PlanItem.find(params[id]) 31 plan_item.update!( 32 params[plan_item].permit(name, description, starts_at, ends_at) 33 ) 34 35 redirect_to plan_items 36 end 37 end 23 32 params[plan_item].permit(name, description, starts_at, ends_at) 26 35 redirect_to plan_items plan_items_controller.rb app/controllers/plan_items_controller.rb 35 redirect_to plan_items 36 end 37 + 38 + private def plan_item_params 39 + params[plan_item].permit(name, description, starts_at, ends_at) 40 + end 41 end 91

8 plan_item_params plan_item_params create app/controllers/plan_items_controller.rb 21 def create 22 - PlanItem.create!( 23 - params[plan_item].permit(name, description, starts_at, ends_at) 24 - ) 22 + PlanItem.create!(plan_item_params) 23 24 redirect_to plan_items 25 end update app/controllers/plan_items_controller.rb 27 def update 28 plan_item = PlanItem.find(params[id]) 29 - plan_item.update!( 30 - params[plan_item].permit(name, description, starts_at, ends_at) 31 - ) 29 + plan_item.update!(plan_item_params) 30 31 redirect_to plan_items 32 end 92

8.3 8.3 ERB partial 1 lessons hello config/routes.rb config/routes.rb 1 Rails.application.routes.draw do 2 root 'top#index' 3 get 'lessons/form' => 'lessons#form' 4 get 'lessons/register' => 'lessons#register' 5 + get 'lessons/hello' => 'lessons#hello' 6 resources plan_items, 7 only [ index, new, show, edit, create, update ] 8 end app/controllers lessons_controller.rb app/controllers/lessons_controller.rb 5 def register 6 @user_name = params[user_name] 7 end 8 9 + def hello 10 + end 11 end app/views/lessons hello.html.erb 93

8 app/views/lessons/hello.html.erb (New) 1 <div class='card'> 2 <div class='card-block'> 3 <%= render 'content' %> 4 </div> 5 </div> app/views/lessons _content.html.erb _ app/views/lessons/_content.html.erb (New) 1 <p class='card-text'>hello, world!</p> CSS card card-block card-text Bootstrap Card 9 http//localhost3000/lessons/hello 8.1 8.1 lessons#hello hello.html.erb 3 <%= render 'content' %> ERB render HTML 94

8.4 _.html.erb _content.html.erb app/views/lessons _content.html.erb hello.html.erb 3 app/views app/views/shared _notes.html.erb <%= render 'shared/notes' %> 8.4 render 2 hello.html.erb app/views/lessons/hello.html.erb 1 <div class='card m-1'> 2 <div class='card-block'> 3 - <%= render 'content' %> 3 + <%= render 'content', name 'Alice' %> 4 + <%= render 'content', name 'Bob' %> 5 </div> 6 </div> 4 render 2 { name 'Alice' } name 'Alice' _content.html.erb 95

8 app/views/lessons/_content.html.erb 1 - <p class='card-text'>hello, world!</p> 1 + <p class='card-text'>hello, <%= name %>!</p> http//localhost3000/lessons/hello 8.2 8.2 _content.html.erb <%= name %> 'Alice' 'Bob' 8.5 PicoPlanner ERB app/views/plan_items new.html.erb edit.html.erb new.html.erb 2 23 app/views/plan_items/new.html.erb 1 <%= form_for @plan_item do f %> 2 - <div class='form-group'> 3 - <%= f.label name, ' ' %> 4 - <%= f.text_field name, class 'form-control', required true %> 17 - <div class='form-group'> 18 - <%= f.label ends_at, ' ' %> 96

8.5 19 - <div class='input-group date datetime-picker'> 20 - <%= f.text_field ends_at, class 'form-control', required true %> 21 - <span class='input-group-addon'><i class='fa fa-calendar'></i></span> 22 - </div> 23 - </div> 2 <div class='form-group'> 3 <%= f.submit ' ', class 'btn btn-success' %> 4 </div> 5 <% end %> _fields.html.erb 2 app/views/plan_items/_fields.html.erb (New) 1 <div class='form-group'> 2 <%= f.label name, ' ' %> 3 <%= f.text_field name, class 'form-control', required true %> 16 <div class='form-group'> 17 <%= f.label ends_at, ' ' %> 18 <div class='input-group date datetime-picker'> 19 <%= f.text_field ends_at, class 'form-control', required true %> 20 <span class='input-group-addon'><i class='fa fa-calendar'></i></span> 21 </div> 22 </div> new.html.erb app/views/plan_items/new.html.erb 1 <%= form_for @plan_item do f %> 2 + <%= render 'fields', f f %> 3 <div class='form-group'> 4 <%= f.submit ' ', class 'btn btn-success' %> 5 </div> 6 <% end %> render 2 { f f } 97

8 f f new.html.erb edit.html.erb 2 23 app/views/plan_items/edit.html.erb 1 <%= form_for @plan_item do f %> 2 - <div class='form-group'> 3 - <%= f.label name, ' ' %> 4 - <%= f.text_field name, class 'form-control', required true %> 17 - <div class='form-group'> 18 - <%= f.label ends_at, ' ' %> 19 - <div class='input-group date datetime-picker'> 20 - <%= f.text_field ends_at, class 'form-control', required true %> 21 - <span class='input-group-addon'><i class='fa fa-calendar'></i></span> 22 - </div> 23 - </div> 2 <div class='form-group'> 3 <%= f.submit ' ', class 'btn btn-success' %> 4 </div> 5 <% end %> edit.html.erb app/views/plan_items/edit.html.erb 1 <%= form_for @plan_item do f %> 2 + <%= render 'fields', f f %> 3 <div class='form-group'> 4 <%= f.submit ' ', class 'btn btn-success' %> 5 </div> 6 <% end %> 98

8.6 8.6 app/views/plan_items index.html.erb index.html.erb 8 10 app/views/plan_items/index.html.erb 7 <div class='col-xs-4 hidden-md-up text-xs-right'> 8 - <%= link_to [ edit, item ] do %> 9 - <i class='fa fa-pencil-square fa-lg'></i> 10 - <% end %> 8 </div> app/views/plan_items _xs_toolbar.html.erb 6 app/views/plan_items/_xs_toolbar.html.erb (New) 1 <%= link_to [ edit, item ] do %> 2 <i class='fa fa-pencil-square fa-lg'></i> 3 <% end %> index.html.erb app/views/plan_items/index.html.erb 7 <div class='col-xs-4 hidden-md-up text-xs-right'> 8 + <%= render 'xs_toolbar', item item %> 9 </div> index.html.erb 18 20 99

8 app/views/plan_items/index.html.erb 17 <div class='col-md-3 hidden-sm-down text-xs-right'> 18 - <%= link_to [ edit, item ], class 'btn btn-secondary btn-sm' do %> 19 - <i class='fa fa-pencil-square'></i> 20 - <% end %> 18 </div> app/views/plan_items _md_toolbar.html.erb 6 app/views/plan_items/_md_toolbar.html.erb (New) 1 <%= link_to [ edit, item ], class 'btn btn-secondary btn-sm' do %> 2 <i class='fa fa-pencil-square'></i> 3 <% end %> index.html.erb app/views/plan_items/index.html.erb 17 <div class='col-md-3 hidden-sm-down text-xs-right'> 18 + <%= render 'md_toolbar', item item %> 19 </div> 8.7 100

8.7 app/views/plan_items/show.html.erb 1 <div class='container-fluid plan-item'> 2 <div class='row'> 3 <div class='col-xs-12 hidden-md-up text-xs-right'> 4 <%= link_to plan_items do %> 5 <i class='fa fa-list fa-lg'></i> 6 <% end %> 7 + <%= render 'xs_toolbar', item @plan_item %> 8 </div> 9 <div class='col-md-12 hidden-sm-down text-xs-right'> 10 <%= link_to plan_items, class 'btn btn-secondary btn-sm' do %> 11 <i class='fa fa-list'></i> 12 <% end %> 13 + <%= render 'md_toolbar', item @plan_item %> 14 </div> 15 </div> 8.3 8.3 8.4 101

8 8.4 102