.gitignore と Gemfile 編集
rails generate bootstrap:install less
rails generate rspec:install
spec/rails_helper.rb 編集
Gemfile 編集
rails generate scaffold server name:string
rails generate scaffold advisory server:references email:string
[from now] 2014/11/14 11:45:48

diff --git a/app/controllers/advisories_controller.rb b/app/controllers/advisories_controller.rb
index 7f353aa..f6e7fb1 100644
--- a/app/controllers/advisories_controller.rb
+++ b/app/controllers/advisories_controller.rb
@@ -1,4 +1,5 @@
 class AdvisoriesController < ApplicationController
+  before_filter :load_advisory
   before_action :set_advisory, only: [:show, :edit, :update, :destroy]

   # GET /advisories
@@ -14,7 +15,7 @@ class AdvisoriesController < ApplicationController

   # GET /advisories/new
   def new
-    @advisory = Advisory.new
+    @advisory = @server.advisory.build
   end

   # GET /advisories/1/edit
@@ -24,15 +25,22 @@ class AdvisoriesController < ApplicationController
   # POST /advisories
   # POST /advisories.json
   def create
-    @advisory = Advisory.new(advisory_params)
+    @advisory = @server.advisories.build(advisory_params)

     respond_to do |format|
       if @advisory.save
-        format.html { redirect_to @advisory, notice: 'Advisory was successfully created.' }
+        format.html do
+          redirect_to [@server, @advisory],
+                      notice: 'Advisory was successfully created.'
+        end
+
         format.json { render :show, status: :created, location: @advisory }
       else
         format.html { render :new }
-        format.json { render json: @advisory.errors, status: :unprocessable_entity }
+
+        format.json do
+          render json: @advisory.errors, status: :unprocessable_entity
+        end
       end
     end
   end
@@ -42,11 +50,18 @@ class AdvisoriesController < ApplicationController
   def update
     respond_to do |format|
       if @advisory.update(advisory_params)
-        format.html { redirect_to @advisory, notice: 'Advisory was successfully updated.' }
+        format.html do
+          redirect_to [@server, @advisory],
+                      notice: 'Advisory was successfully updated.'
+        end
+
         format.json { render :show, status: :ok, location: @advisory }
       else
         format.html { render :edit }
-        format.json { render json: @advisory.errors, status: :unprocessable_entity }
+
+        format.json do
+          render json: @advisory.errors, status: :unprocessable_entity
+        end
       end
     end
   end
@@ -56,19 +71,29 @@ class AdvisoriesController < ApplicationController
   def destroy
     @advisory.destroy
     respond_to do |format|
-      format.html { redirect_to advisories_url, notice: 'Advisory was successfully destroyed.' }
+      format.html do
+        redirect_to advisories_url,
+                    notice: 'Advisory was successfully destroyed.'
+      end
+
       format.json { head :no_content }
     end
   end

   private
-    # Use callbacks to share common setup or constraints between actions.
-    def set_advisory
-      @advisory = Advisory.find(params[:id])
-    end

-    # Never trust parameters from the scary internet, only allow the white list through.
-    def advisory_params
-      params.require(:advisory).permit(:server_id, :email)
-    end
+  # Use callbacks to share common setup or constraints between actions.
+  def set_advisory
+    @advisory = @server.advisory.find(params[:id])
+  end
+
+  # Never trust parameters from the scary internet, only allow the
+  # white list through.
+  def advisory_params
+    params.require(:advisory).permit(:server_id, :email)
+  end
+
+  def load_advisory
+    @server = Server.find(params[:server_id])
+  end
 end
diff --git a/app/models/server.rb b/app/models/server.rb
index 120f0fa..6284833 100644
--- a/app/models/server.rb
+++ b/app/models/server.rb
@@ -1,2 +1,3 @@
 class Server < ActiveRecord::Base
+  has_many :advisory
 end
diff --git a/app/views/advisories/_form.html.erb b/app/views/advisories/_form.html.erb
index 948cab3..7a4cb3a 100644
--- a/app/views/advisories/_form.html.erb
+++ b/app/views/advisories/_form.html.erb
@@ -1,7 +1,10 @@
-<%= form_for(@advisory) do |f| %>
+<%= form_for([@server, @advisory]) do |f| %>
   <% if @advisory.errors.any? %>
     <div id="error_explanation">
-      <h2><%= pluralize(@advisory.errors.count, "error") %> prohibited this advisory from being saved:</h2>
+      <h2>
+	<%= pluralize(@advisory.errors.count, "error") %>
+	prohibited this advisory from being saved:
+      </h2>

       <ul>
       <% @advisory.errors.full_messages.each do |message| %>
@@ -13,7 +16,7 @@

   <div class="field">
     <%= f.label :server_id %><br>
-    <%= f.text_field :server_id %>
+    <%= f.text_label :server_id %>
   </div>
   <div class="field">
     <%= f.label :email %><br>
diff --git a/app/views/advisories/index.html.erb b/app/views/advisories/index.html.erb
index ce37126..034a63f 100644
--- a/app/views/advisories/index.html.erb
+++ b/app/views/advisories/index.html.erb
@@ -16,7 +16,11 @@
         <td><%= advisory.email %></td>
         <td><%= link_to 'Show', advisory %></td>
         <td><%= link_to 'Edit', edit_advisory_path(advisory) %></td>
-        <td><%= link_to 'Destroy', advisory, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+
+        <td>
+	  <%= link_to('Destroy', advisory, method: :delete,
+		      data: { confirm: 'Are you sure?' }) %>
+	</td>
       </tr>
     <% end %>
   </tbody>
@@ -24,4 +28,4 @@

 <br>

-<%= link_to 'New Advisory', new_advisory_path %>
+<%= link_to 'New Advisory', new_server_advisory_path %>
diff --git a/app/views/advisories/new.html.erb b/app/views/advisories/new.html.erb
index 4f5bf74..a443af5 100644
--- a/app/views/advisories/new.html.erb
+++ b/app/views/advisories/new.html.erb
@@ -2,4 +2,4 @@

 <%= render 'form' %>

-<%= link_to 'Back', advisories_path %>
+<%= link_to 'Back', server_advisories_path %>
diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb
index dfd50c2..b4f1951 100644
--- a/app/views/servers/show.html.erb
+++ b/app/views/servers/show.html.erb
@@ -5,5 +5,6 @@
   <%= @server.name %>
 </p>

+<%= link_to '通知先', server_advisories_path(@server) %> |
 <%= link_to 'Edit', edit_server_path(@server) %> |
 <%= link_to 'Back', servers_path %>
diff --git a/config/routes.rb b/config/routes.rb
index d99a799..bb05474 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,9 +1,10 @@
 Rails.application.routes.draw do
-  resources :advisories
+  resources :servers do
+    resources :advisories
+  end

-  resources :servers
-
-  # The priority is based upon order of creation: first created -> highest priority.
+  # The priority is based upon order of creation: first created ->
+  # highest priority.
   # See how all your routes lay out with "rake routes".

   # You can have the root of your site routed with "root"
デバッグ情報
server と advisory を連結
rails generate bootstrap:layout application
rails generate bootstrap:themed servers
整形
会社名表示
デバッグ情報
整形
日本語化
`advisory' リンク作成
rails generate bootstrap:themed advisories
server と advisory の連結やり直し