概要 Ruby on Rails Tutorialのエッセンスを自分なりに整理9 [Rails] 基本的なユーザ管理用Modelをテスト駆動で実装してみる http://qiita.com/kidachi_/items/99f2c90788bd931ea3ee の続き。 Ruby on Rails Tutorial(chapter7) http://railstutorial.jp/chapters/sign-up?version=4.0#code-after_save_tests 分かること フォームの生成方法 フォームを介してやりとりされるデータの形 Strong Parametersとは何か 基本的なフォーム まず、ユーザ登録を行うフォームを見てみる。 UsersController 二つのメソッドを準備。 new(GET) ユーザ登録ページを生成 - create(POST) ne
railstutorialはRuby on RailsとデファクトスタンダードなGemを使ってTwitter風アプリケーションを作るということを題材に、実際の仕事の開発でも行うGitHub Flowや振る舞い駆動開発をしながら、Webアプリケーション開発を学ぶチュートリアル。 Ruby on Rails チュートリアル:実例を使って Rails を学ぼう 長かったー。一週間以上かかった。本文中にも書いてあったが、飛ばし読みできない。とても濃厚なチュートリアルなので、1日1章ペース。休みの日に8,9,10章を一気にやったら大変過ぎて10章はあまり頭に入ってこなかった。中ボスと呼ばれている演習は全て飛ばした。 勉強になった点や疑問点、ハマった点をメモしながらやってみた。 メモ http://yuheikagaya.hatenablog.jp/entry/2014/10/15/005554 ht
第11章ユーザーをフォローする この章では、他のユーザーをフォロー (およびフォロー解除) できるソーシャルレイヤーを追加し、各ユーザーのHomeページに、現在フォロー中のユーザーのステータスフィードを表示できるようにして、サンプルアプリケーションのコアを完成させます。また、自分をフォローしているユーザーと、自分がフォローしているユーザーを同時に表示できるようにします。ユーザー間のリレーションをモデリングする方法については11.1で説明します。続いてWebインターフェイスの作成方法について、Ajaxの紹介と合わせて11.2で説明します。最終的に、完全に動作するステータスフィードの開発は11.3で完了します。 この最終章では、本書の中で最も難易度の高い手法をいくつか使用しています。その中には、ステータスフィード作成のためにRuby/SQLを「だます」テクニックも含まれます。この章の例全体にわ
第10章ユーザーのマイクロポスト 第9章ではUsersリソース用のRESTアクションを完成させました。次はいよいよ、ユーザーのマイクロポストリソースをすべて追加しましょう1。第2章では、特定のユーザーに関連付けられたいくつかの簡単なメッセージがありました。この章では、2.3で記述したMicropostデータモデルを作成し、Userモデルとhas_manyおよびbelongs_toメソッドを使って関連付けを行い、さらに、結果を処理し表示するために必要なフォームとその部品を作成します。 第11章では、マイクロポストのフィードを受け取るために、ユーザーをフォローするという概念を導入し、Twitterのミニクローンを完成させます。 Git をバージョン管理に使っている場合は、いつものようにトピックブランチを作成しておきましょう。
第7章ユーザー登録 Userモデルができあがったので、いよいよWebサイトになくてはならないユーザー登録機能を追加しましょう。7.2ではHTMLフォームを使用して登録情報をWebアプリケーションに送信します。続いて7.4ではユーザーを新規作成して情報をデータベースに保存します。ユーザー登録手続きの最後には、作成されたユーザーの新しいプロファイルを表示できるようにするために、ユーザーを表示するためのページを作成し、ユーザー用のRESTアーキテクチャを実装する第一歩を踏み出します (2.2.2)。これまでと同様、開発と同時にテストも作成します。RSpecとCapybaraの適用範囲を拡大し、簡潔かつ表現力豊かな結合テストを作成します。 ユーザープロファイルページを作成するには、その前にデータベースにユーザーが登録されている必要があります。これはいわゆる「卵が先か鶏が先か」問題です。このWebサ
第9章 ユーザーの更新・表示・削除 この章では、Usersリソース用のRESTアクション (表7.1) のうち、これまで未実装だったedit、update、index、destroyアクションを追加し、RESTアクションを完成させます。まずはユーザーが自分のプロファイルを自分で更新できるようにします。これにより、第8章で実装した認証用のコードによるセキュリティモデルを適用する機会を自然に提供することもできます。次に、すべてのユーザーを一覧できるようにします (もちろん認証を要求します)。これはサンプルデータとページネーション (pagnation) を導入する動機にもなります。最後に、ユーザーを削除し、データベースから完全に消去する機能を追加します。ユーザーの削除はどのユーザーにも許可できるものではないので、管理ユーザー (admin) の特権クラスを作成し、このユーザーにのみ削除を許可す
第4章Rails風味のRuby この章では、第3章で使用した例を基に、Railsにおいて重要となるRubyのさまざまな要素について探っていくことにしましょう。Rubyは巨大な仕様を持つ言語ですが、幸い、Rails開発者にとって必要な知識は比較的少なくて済みます。さらに、Railsのために必要なRubyの知識は、通常のRubyを学ぶ過程とは異なります。動的なWebアプリを作ることができればそれでよいというのであれば、まずRailsを学ぶようにし、Rubyについては当分の間、必要が生じた場合にのみ学習することをお勧めします。そうではなく、真のRailsエキスパートになりたいのであれば、Rubyをさらに深いレベルまで理解する必要があります。本書は、そのための開発技術の基礎を築く助けになるでしょう。1.1.1でも示したように、Railsチュートリアル を終えた後には「 Beginning Ruby
第8章サインイン、サインアウト 第7章でWebサイトでの新規ユーザー登録が行えるようになりましたので、今度はユーザーがサインインとサインアウトを行えるようにしましょう。これにより、サインインの状態と現在のユーザーidに応じて動作を変更できるようになります。たとえば、この章では、サイトのヘッダー部分にサインイン/サインアウトのリンクとプロファイルへのリンクを表示するようにします。第10章では、サインインしたユーザーidを使用して、そのユーザーに関連付けられたマイクロポストを作成します。また第11章では、現在のユーザーが他のユーザーをフォローして、マイクロポストのフィードを受け取ることができるようにします。 ユーザーがサインインすることでセキュリティモデルも実装され、サインインしているユーザーidに基づいて、特定のページへのアクセスを制限することもできます。第9章でも説明しますが、たとえばサイ
第6章ユーザーのモデルを作成する 第5章では、新しいユーザーを作成するためのスタブページを作ったところで終わりました (5.4)。これから4つの章を通して、ユーザー登録ページを作っていくことにしましょう。最初の一番重要なステップは、サイトのユーザー用のデータモデルの作成と、データを保存する手段の確保です。第7章では、ユーザーがサイトにユーザー登録できるようにし、ユーザープロファイルのためのページを作成します。ユーザー登録ができるようになると、次にサインイン、サインアウトもできるようにします (第8章)。そして第9章 (9.2.1) では、不正なアクセスから守る方法を学びます。まとめると、第6章から第9章を通して、Railsのログインと認証のシステムをひととおり開発します。ご存知の方もいると思いますが、Railsでは既にさまざまな認証方法が利用可能です。コラム 6.1では、最初に少なくとも一
第2章デモアプリケーション この章では、Railsの強力な機能をいくつか紹介するためのデモアプリケーションを作成します。scaffoldジェネレータというスクリプトを使ってアプリケーションをすばやく生成する事により、高度なRailsプログラミングとWebプログラミングの概要を学びます。コラム1.1で述べたように、本書の以後の章では基本的にこの逆のアプローチを取り、少しずつアプリケーションを作りながら各段階と概念を説明する予定ですが、scaffoldはRailsアプリケーションの概要を素早くつかむには最適なので、この章でのみあえて使用することにします。生成されたRailsアプリケーションはブラウザのアドレスバーにURLを入力すれば動かすことができるので、これによりRailsアプリの構造、そしてRailsで推奨されているRESTアーキテクチャに関する洞察を得ることにします。 デモアプリケーショ
※最新版の『Ruby on Rails チュートリアル第6版:実例を使ってRailsを学ぼう』が販売中です。 関連サイト本書の関連サイトがあります。 Rails チュートリアル: http://railstutorial.jp/ヘルプページ: http://railstutorial.jp/helpまた、本書よりさらに踏み込んだRuby on Rails公式ガイド、『Railsガイド』も好評発売中です。 内容紹介本書は、Rails 創始者の David Heinemeier Hansson に推奨され、世界中で利用されている Ruby on Rails Tutorial の和訳本です。 本書では、Twitter のようなマイクロブログサービスを題材にして、実際に手を動かしながら学んでいく、チュートリアル形式を採用しています。また、本書は実践的な内容を重視しているので、Ruby や Rail
Rails 7 に対応した第7版Railsチュートリアルをリリースしました! プロダクト開発が学べる大型チュートリアルで学んでみませんか? よくあるご質問 前提とする知識などはありますか? Git/GitHubの使い方やRubyの文法などはWebテキスト中で解説されていますが、難しいと感じた方のための実践入門シリーズもあります。学習ロードマップを参考に自分流の学習計画を立てるのもオススメです。 Rails 7 対応の解説動画は2023年4月から1章ずつ先行リリースされていきます。 買い切りですか? 月額課金 (サブスク) ですか? 書店にある本や雑誌と同じで、買い切り型となります。月額課金 (サブスク) ではないため、毎月の課金は発生しません。 バージョンアップ版がリリースされたら無料アップグレードできますか? いいえ、解説動画と同じでアップグレードは有償対応となります。コンテンツの継続的
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く