• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ

よく使われているワード(クリックで追加)

javaandroidc++linuxc#windowsobjective-ccocoaqt誰得pythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Web appl using RoR 3.2.14


コミットメタ情報

リビジョンd9194a31dd73e37996e89e85008f66307458e027 (tree)
日時2013-08-28 02:20:41
作者stellecadente <yoichi.k@stel...>
コミッターstellecadente

ログメッセージ

added other associations

変更サマリ

差分

--- a/.gitignore
+++ b/.gitignore
@@ -15,5 +15,5 @@
1515 /tmp
1616
1717 # Ignore Shell Scripts
18-/*.sh
18+*.sh
1919
--- a/app/controllers/mountains_controller.rb
+++ b/app/controllers/mountains_controller.rb
@@ -4,7 +4,7 @@ class MountainsController < ApplicationController
44 def index
55 # @mountains = Mountain.all
66 @mountains = Mountain.order('id ASC').
7- paginate(:page => params[:page], :per_page => 10)
7+ paginate(:page => params[:page], :per_page => 20)
88
99 respond_to do |format|
1010 format.html # index.html.erb
--- a/app/controllers/records_controller.rb
+++ b/app/controllers/records_controller.rb
@@ -3,6 +3,8 @@ class RecordsController < ApplicationController
33 # GET /records.json
44 def index
55 @records = Record.all
6+ @records = Record.order('id ASC').
7+ paginate(:page => params[:page], :per_page => 10)
68
79 respond_to do |format|
810 format.html # index.html.erb
@@ -80,4 +82,10 @@ class RecordsController < ApplicationController
8082 format.json { head :no_content }
8183 end
8284 end
85+
86+ # Show one's records of conquering mountains
87+ def conquer
88+ @user = User.where(:name => 'yoichi.k' ).first
89+ end
90+
8391 end
--- a/app/models/blog.rb
+++ b/app/models/blog.rb
@@ -2,4 +2,5 @@ class Blog < ActiveRecord::Base
22 attr_accessible :body, :id, :issue_dt, :title, :user_id, :mountain_id
33 belongs_to :mountain
44 belongs_to :user
5+ has_many :blog_comments
56 end
--- a/app/models/blog_comment.rb
+++ b/app/models/blog_comment.rb
@@ -1,3 +1,4 @@
11 class BlogComment < ActiveRecord::Base
22 attr_accessible :blog_id, :body, :fl_publish, :id, :issue_dt, :title, :user_id
3+ belongs_to :blogs
34 end
--- a/app/models/mountain.rb
+++ b/app/models/mountain.rb
@@ -2,4 +2,5 @@ class Mountain < ActiveRecord::Base
22 attr_accessible :district, :elevation, :fl_100meizan, :fl_200meizan, :fl_300meizan, :fl_aizu, :fl_gumma, :fl_hana, :fl_hokkaido, :fl_kansai, :fl_kanto, :fl_kyuushuu, :fl_niigata, :fl_shikoku, :fl_shinhana, :fl_shinhyaku, :fl_tochigi, :fl_tohoku, :fl_utsukushima, :fl_yama1000, :fl_yamanashi, :id, :kana, :latitude, :longitude, :map025, :map050, :map200, :name1, :name2, :name3, :number_300meizan, :prefs, :uname
33 has_many :blogs
44 has_many :users, :through => :blogs
5+ has_many :users, :through => :records
56 end
--- /dev/null
+++ b/app/models/mountains_records.rb
@@ -0,0 +1,5 @@
1+class MountainsRecords < ActiveRecord::Base
2+ belongs_to :mountain
3+ belongs_to :record
4+ # attr_accessible :title, :body
5+end
--- a/app/models/record.rb
+++ b/app/models/record.rb
@@ -1,3 +1,4 @@
11 class Record < ActiveRecord::Base
22 attr_accessible :body, :end_d, :id, :mountain_id, :publish_d, :start_d, :title, :user_id
3+ belongs_to :users
34 end
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -2,4 +2,5 @@ class User < ActiveRecord::Base
22 attr_accessible :authority, :birth_d, :email, :id, :name, :password, :password_digest, :pref, :realname, :register_d, :selfintro
33 has_many :blogs
44 has_many :mountains, :through => :blogs
5+ has_many :records
56 end
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -13,7 +13,8 @@
1313
1414 <hr />
1515 <div>
16- <p>Powered by Ruby on Rails</p>
16+ <p><%= t 'application.footer' %></p>
17+ <p><%= t 'application.copyright' %></p>
1718 </div>
1819 </body>
1920 </html>
--- a/app/views/mountains/_form_index_short.html.erb
+++ b/app/views/mountains/_form_index_short.html.erb
@@ -5,7 +5,7 @@
55 <th><%= t "attributes.uname" %></th>
66 <th><%= t "attributes.elevation" %></th>
77 <th><%= t "attributes.district" %></th>
8- <th><%= t "attributes.number_300meizan" %></th>
8+ <th><%= "通番" %></th>
99 <th><%= t "attributes.100meizan" %></th>
1010 <th><%= t "attributes.200meizan" %></th>
1111 <th><%= t "attributes.300meizan" %></th>
@@ -18,7 +18,7 @@
1818
1919 <tbody>
2020 <% @mountains.each do |mountain| %>
21- <tr style="background-color:<%= cycle('#DDddDD', '#FFff99') %>">
21+ <tr style="background-color:<%= cycle('#DDddDD', '#FFff55') %>">
2222 <td width=10 align=right><%= mountain.id %></td>
2323 <td width=140><%= mountain.uname %></td>
2424 <td><%= mountain.elevation %>m</td>
--- a/app/views/records/_form.html.erb
+++ b/app/views/records/_form.html.erb
@@ -41,7 +41,7 @@
4141 </div>
4242 <div class="field">
4343 <%= f.label :body %><br />
44- <%= f.text_field :body %>
44+ <%= f.text_area :body, {:cols=>40, :rows=>3 } %>
4545 </div>
4646 <div class="actions">
4747 <%= f.submit %>
--- /dev/null
+++ b/app/views/records/conquer.html.erb
@@ -0,0 +1,12 @@
1+<h1>「<%= @user.name %>」が登った山</h1>
2+<hr />
3+<p id="notice"><%= notice %></p>
4+
5+<% @user.mountains.each do |mountain| %>
6+ <h3><%= mountain.uname %></h3>
7+ <p>
8+ 標高: <%= mountain.elevation %>m,
9+ 山域名:<%= mountain.district %>
10+ </p>
11+<% end %>
12+
--- a/app/views/records/edit.html.erb
+++ b/app/views/records/edit.html.erb
@@ -1,6 +1,7 @@
11 <h1>Editing record</h1>
2+<%= link_to 'Show', @record %> |
3+<%= link_to 'Back', records_path %>
4+<hr />
25
36 <%= render 'form' %>
47
5-<%= link_to 'Show', @record %> |
6-<%= link_to 'Back', records_path %>
--- a/app/views/records/index.html.erb
+++ b/app/views/records/index.html.erb
@@ -1,4 +1,6 @@
11 <h1>Listing records</h1>
2+<%= link_to 'New Record', new_record_path %>
3+<hr />
24
35 <table>
46 <tr>
@@ -16,7 +18,7 @@
1618 </tr>
1719
1820 <% @records.each do |record| %>
19- <tr>
21+ <tr style="background-color:<%= cycle('#DDddDD', '#99ffFF') %>">
2022 <td><%= record.id %></td>
2123 <td><%= record.mountain_id %></td>
2224 <td><%= record.user_id %></td>
@@ -30,8 +32,7 @@
3032 <td><%= link_to 'Destroy', record, method: :delete, data: { confirm: 'Are you sure?' } %></td>
3133 </tr>
3234 <% end %>
35+<%= will_paginate @users %>
3336 </table>
3437
3538 <br />
36-
37-<%= link_to 'New Record', new_record_path %>
--- a/app/views/records/new.html.erb
+++ b/app/views/records/new.html.erb
@@ -1,5 +1,6 @@
11 <h1>New record</h1>
2+<%= link_to 'Back', records_path %>
3+<hr />
24
35 <%= render 'form' %>
46
5-<%= link_to 'Back', records_path %>
--- a/app/views/records/show.html.erb
+++ b/app/views/records/show.html.erb
@@ -1,4 +1,7 @@
1+<%= link_to 'Edit', edit_record_path(@record) %> |
2+<%= link_to 'Back', records_path %>
13 <p id="notice"><%= notice %></p>
4+<hr />
25
36 <p>
47 <b>Id:</b>
@@ -41,5 +44,3 @@
4144 </p>
4245
4346
44-<%= link_to 'Edit', edit_record_path(@record) %> |
45-<%= link_to 'Back', records_path %>
--- a/config/locales/ja.yml
+++ b/config/locales/ja.yml
@@ -279,6 +279,8 @@ ja:
279279 link: '編集'
280280 application:
281281 title: キスゲプロジェクト
282+ footer: Powered by Ruby on Rails
283+ copyright: (C)Yoichi Kanno, 2013
282284 users:
283285 title:
284286 list: 〈メンバー〉データ一覧表
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -20,7 +20,16 @@ Kisuge::Application.routes.draw do
2020 post 'destroy'
2121 end
2222
23- resources :records
23+ resources :records do
24+ collection do
25+ get 'conquer' => 'records#conquer'
26+ end
27+ get 'index'
28+ get 'show'
29+ post 'new'
30+ post 'edit'
31+ post 'destroy'
32+ end
2433
2534
2635 # The priority is based upon order of creation:
--- a/create_model_mountains-blogs.sh
+++ /dev/null
@@ -1,6 +0,0 @@
1-#!/bin/bash
2-
3-rails generate model mountains-blogs \
4- mountain_id:references \
5- brog_id:references \
6-
--- a/create_scaffold_mountains.sh
+++ /dev/null
@@ -1,38 +0,0 @@
1-#!/bin/bash
2-
3-rails generate scaffold mountains \
4- id:integer \
5- uname:string \
6- kana:string \
7- name1:string \
8- name2:string \
9- name3:string \
10- elevation:integer \
11- number_300meizan \
12- district:string \
13- latitude:float \
14- longitude:float \
15- prefs:string \
16- map200:string \
17- map050:string \
18- map025:string \
19- fl_yama1000:boolean \
20- fl_100meizan:boolean \
21- fl_200meizan:boolean \
22- fl_300meizan:boolean \
23- fl_hana:boolean \
24- fl_shinhana:boolean \
25- fl_shinhyaku:boolean \
26- fl_kanto:boolean \
27- fl_kansai:boolean \
28- fl_kyuushuu:boolean \
29- fl_yamanashi:boolean \
30- fl_tohoku:boolean \
31- fl_niigata:boolean \
32- fl_utsukushima:boolean \
33- fl_aizu:boolean \
34- fl_hokkaido:boolean \
35- fl_shikoku:boolean \
36- fl_tochigi:boolean \
37- fl_gumma:boolean \
38-
--- a/create_scaffold_users.sh
+++ /dev/null
@@ -1,14 +0,0 @@
1-#!/bin/bash
2-
3-rails generate scaffold users \
4- id:integer \
5- name:string \
6- realname:string \
7- password:string \
8- password_digest:string \
9- birth_d:date \
10- register_d:date \
11- authority:string \
12- email:string \
13- pref:string \
14- selfintro:string \
--- a/create_scaffolds.sh
+++ b/create_scaffolds.sh
@@ -80,3 +80,7 @@ rails generate model mountains-blogs \
8080 mountain:references \
8181 blog:references \
8282
83+rails generate model mountains-records \
84+ mountain:references \
85+ record:references \
86+
--- /dev/null
+++ b/db/migrate/20130827165652_create_mountains_records.rb
@@ -0,0 +1,11 @@
1+class CreateMountainsRecords < ActiveRecord::Migration
2+ def change
3+ create_table :mountains_records, :id => false do |t|
4+ t.references :mountain
5+ t.references :record
6+
7+ end
8+ add_index :mountains_records, :mountain_id
9+ add_index :mountains_records, :record_id
10+ end
11+end
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
1111 #
1212 # It's strongly recommended to check this file into your version control system.
1313
14-ActiveRecord::Schema.define(:version => 20130827105700) do
14+ActiveRecord::Schema.define(:version => 20130827165652) do
1515
1616 create_table "blog_comments", :force => true do |t|
1717 t.integer "blog_id"
@@ -80,6 +80,14 @@ ActiveRecord::Schema.define(:version => 20130827105700) do
8080 add_index "mountains_blogs", ["blog_id"], :name => "index_mountains_blogs_on_blog_id"
8181 add_index "mountains_blogs", ["mountain_id"], :name => "index_mountains_blogs_on_mountain_id"
8282
83+ create_table "mountains_records", :id => false, :force => true do |t|
84+ t.integer "mountain_id"
85+ t.integer "record_id"
86+ end
87+
88+ add_index "mountains_records", ["mountain_id"], :name => "index_mountains_records_on_mountain_id"
89+ add_index "mountains_records", ["record_id"], :name => "index_mountains_records_on_record_id"
90+
8391 create_table "records", :force => true do |t|
8492 t.string "mountain_id"
8593 t.string "user_id"
--- /dev/null
+++ b/test/fixtures/mountains_records.yml
@@ -0,0 +1,17 @@
1+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2+
3+one:
4+ mountain_id: 2
5+ record_id: 1
6+
7+two_id:
8+ mountain_id: 1
9+ record_id: 3
10+
11+three_id:
12+ mountain_id: 3
13+ record_id: 4
14+
15+four_id:
16+ mountain_id: 289
17+ record_id: 5
--- /dev/null
+++ b/test/unit/mountains_records_test.rb
@@ -0,0 +1,7 @@
1+require 'test_helper'
2+
3+class MountainsRecordsTest < ActiveSupport::TestCase
4+ # test "the truth" do
5+ # assert true
6+ # end
7+end