Web appl using RoR 3.2.14
リビジョン | d9194a31dd73e37996e89e85008f66307458e027 (tree) |
---|---|
日時 | 2013-08-28 02:20:41 |
作者 | ![]() |
コミッター | stellecadente |
added other associations
@@ -15,5 +15,5 @@ | ||
15 | 15 | /tmp |
16 | 16 | |
17 | 17 | # Ignore Shell Scripts |
18 | -/*.sh | |
18 | +*.sh | |
19 | 19 |
@@ -4,7 +4,7 @@ class MountainsController < ApplicationController | ||
4 | 4 | def index |
5 | 5 | # @mountains = Mountain.all |
6 | 6 | @mountains = Mountain.order('id ASC'). |
7 | - paginate(:page => params[:page], :per_page => 10) | |
7 | + paginate(:page => params[:page], :per_page => 20) | |
8 | 8 | |
9 | 9 | respond_to do |format| |
10 | 10 | format.html # index.html.erb |
@@ -3,6 +3,8 @@ class RecordsController < ApplicationController | ||
3 | 3 | # GET /records.json |
4 | 4 | def index |
5 | 5 | @records = Record.all |
6 | + @records = Record.order('id ASC'). | |
7 | + paginate(:page => params[:page], :per_page => 10) | |
6 | 8 | |
7 | 9 | respond_to do |format| |
8 | 10 | format.html # index.html.erb |
@@ -80,4 +82,10 @@ class RecordsController < ApplicationController | ||
80 | 82 | format.json { head :no_content } |
81 | 83 | end |
82 | 84 | end |
85 | + | |
86 | + # Show one's records of conquering mountains | |
87 | + def conquer | |
88 | + @user = User.where(:name => 'yoichi.k' ).first | |
89 | + end | |
90 | + | |
83 | 91 | end |
@@ -2,4 +2,5 @@ class Blog < ActiveRecord::Base | ||
2 | 2 | attr_accessible :body, :id, :issue_dt, :title, :user_id, :mountain_id |
3 | 3 | belongs_to :mountain |
4 | 4 | belongs_to :user |
5 | + has_many :blog_comments | |
5 | 6 | end |
@@ -1,3 +1,4 @@ | ||
1 | 1 | class BlogComment < ActiveRecord::Base |
2 | 2 | attr_accessible :blog_id, :body, :fl_publish, :id, :issue_dt, :title, :user_id |
3 | + belongs_to :blogs | |
3 | 4 | end |
@@ -2,4 +2,5 @@ class Mountain < ActiveRecord::Base | ||
2 | 2 | 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 |
3 | 3 | has_many :blogs |
4 | 4 | has_many :users, :through => :blogs |
5 | + has_many :users, :through => :records | |
5 | 6 | end |
@@ -0,0 +1,5 @@ | ||
1 | +class MountainsRecords < ActiveRecord::Base | |
2 | + belongs_to :mountain | |
3 | + belongs_to :record | |
4 | + # attr_accessible :title, :body | |
5 | +end |
@@ -1,3 +1,4 @@ | ||
1 | 1 | class Record < ActiveRecord::Base |
2 | 2 | attr_accessible :body, :end_d, :id, :mountain_id, :publish_d, :start_d, :title, :user_id |
3 | + belongs_to :users | |
3 | 4 | end |
@@ -2,4 +2,5 @@ class User < ActiveRecord::Base | ||
2 | 2 | attr_accessible :authority, :birth_d, :email, :id, :name, :password, :password_digest, :pref, :realname, :register_d, :selfintro |
3 | 3 | has_many :blogs |
4 | 4 | has_many :mountains, :through => :blogs |
5 | + has_many :records | |
5 | 6 | end |
@@ -13,7 +13,8 @@ | ||
13 | 13 | |
14 | 14 | <hr /> |
15 | 15 | <div> |
16 | - <p>Powered by Ruby on Rails</p> | |
16 | + <p><%= t 'application.footer' %></p> | |
17 | + <p><%= t 'application.copyright' %></p> | |
17 | 18 | </div> |
18 | 19 | </body> |
19 | 20 | </html> |
@@ -5,7 +5,7 @@ | ||
5 | 5 | <th><%= t "attributes.uname" %></th> |
6 | 6 | <th><%= t "attributes.elevation" %></th> |
7 | 7 | <th><%= t "attributes.district" %></th> |
8 | - <th><%= t "attributes.number_300meizan" %></th> | |
8 | + <th><%= "通番" %></th> | |
9 | 9 | <th><%= t "attributes.100meizan" %></th> |
10 | 10 | <th><%= t "attributes.200meizan" %></th> |
11 | 11 | <th><%= t "attributes.300meizan" %></th> |
@@ -18,7 +18,7 @@ | ||
18 | 18 | |
19 | 19 | <tbody> |
20 | 20 | <% @mountains.each do |mountain| %> |
21 | - <tr style="background-color:<%= cycle('#DDddDD', '#FFff99') %>"> | |
21 | + <tr style="background-color:<%= cycle('#DDddDD', '#FFff55') %>"> | |
22 | 22 | <td width=10 align=right><%= mountain.id %></td> |
23 | 23 | <td width=140><%= mountain.uname %></td> |
24 | 24 | <td><%= mountain.elevation %>m</td> |
@@ -41,7 +41,7 @@ | ||
41 | 41 | </div> |
42 | 42 | <div class="field"> |
43 | 43 | <%= f.label :body %><br /> |
44 | - <%= f.text_field :body %> | |
44 | + <%= f.text_area :body, {:cols=>40, :rows=>3 } %> | |
45 | 45 | </div> |
46 | 46 | <div class="actions"> |
47 | 47 | <%= f.submit %> |
@@ -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 | + |
@@ -1,6 +1,7 @@ | ||
1 | 1 | <h1>Editing record</h1> |
2 | +<%= link_to 'Show', @record %> | | |
3 | +<%= link_to 'Back', records_path %> | |
4 | +<hr /> | |
2 | 5 | |
3 | 6 | <%= render 'form' %> |
4 | 7 | |
5 | -<%= link_to 'Show', @record %> | | |
6 | -<%= link_to 'Back', records_path %> |
@@ -1,4 +1,6 @@ | ||
1 | 1 | <h1>Listing records</h1> |
2 | +<%= link_to 'New Record', new_record_path %> | |
3 | +<hr /> | |
2 | 4 | |
3 | 5 | <table> |
4 | 6 | <tr> |
@@ -16,7 +18,7 @@ | ||
16 | 18 | </tr> |
17 | 19 | |
18 | 20 | <% @records.each do |record| %> |
19 | - <tr> | |
21 | + <tr style="background-color:<%= cycle('#DDddDD', '#99ffFF') %>"> | |
20 | 22 | <td><%= record.id %></td> |
21 | 23 | <td><%= record.mountain_id %></td> |
22 | 24 | <td><%= record.user_id %></td> |
@@ -30,8 +32,7 @@ | ||
30 | 32 | <td><%= link_to 'Destroy', record, method: :delete, data: { confirm: 'Are you sure?' } %></td> |
31 | 33 | </tr> |
32 | 34 | <% end %> |
35 | +<%= will_paginate @users %> | |
33 | 36 | </table> |
34 | 37 | |
35 | 38 | <br /> |
36 | - | |
37 | -<%= link_to 'New Record', new_record_path %> |
@@ -1,5 +1,6 @@ | ||
1 | 1 | <h1>New record</h1> |
2 | +<%= link_to 'Back', records_path %> | |
3 | +<hr /> | |
2 | 4 | |
3 | 5 | <%= render 'form' %> |
4 | 6 | |
5 | -<%= link_to 'Back', records_path %> |
@@ -1,4 +1,7 @@ | ||
1 | +<%= link_to 'Edit', edit_record_path(@record) %> | | |
2 | +<%= link_to 'Back', records_path %> | |
1 | 3 | <p id="notice"><%= notice %></p> |
4 | +<hr /> | |
2 | 5 | |
3 | 6 | <p> |
4 | 7 | <b>Id:</b> |
@@ -41,5 +44,3 @@ | ||
41 | 44 | </p> |
42 | 45 | |
43 | 46 | |
44 | -<%= link_to 'Edit', edit_record_path(@record) %> | | |
45 | -<%= link_to 'Back', records_path %> |
@@ -279,6 +279,8 @@ ja: | ||
279 | 279 | link: '編集' |
280 | 280 | application: |
281 | 281 | title: キスゲプロジェクト |
282 | + footer: Powered by Ruby on Rails | |
283 | + copyright: (C)Yoichi Kanno, 2013 | |
282 | 284 | users: |
283 | 285 | title: |
284 | 286 | list: 〈メンバー〉データ一覧表 |
@@ -20,7 +20,16 @@ Kisuge::Application.routes.draw do | ||
20 | 20 | post 'destroy' |
21 | 21 | end |
22 | 22 | |
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 | |
24 | 33 | |
25 | 34 | |
26 | 35 | # The priority is based upon order of creation: |
@@ -1,6 +0,0 @@ | ||
1 | -#!/bin/bash | |
2 | - | |
3 | -rails generate model mountains-blogs \ | |
4 | - mountain_id:references \ | |
5 | - brog_id:references \ | |
6 | - |
@@ -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 | - |
@@ -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 \ |
@@ -80,3 +80,7 @@ rails generate model mountains-blogs \ | ||
80 | 80 | mountain:references \ |
81 | 81 | blog:references \ |
82 | 82 | |
83 | +rails generate model mountains-records \ | |
84 | + mountain:references \ | |
85 | + record:references \ | |
86 | + |
@@ -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 |
@@ -11,7 +11,7 @@ | ||
11 | 11 | # |
12 | 12 | # It's strongly recommended to check this file into your version control system. |
13 | 13 | |
14 | -ActiveRecord::Schema.define(:version => 20130827105700) do | |
14 | +ActiveRecord::Schema.define(:version => 20130827165652) do | |
15 | 15 | |
16 | 16 | create_table "blog_comments", :force => true do |t| |
17 | 17 | t.integer "blog_id" |
@@ -80,6 +80,14 @@ ActiveRecord::Schema.define(:version => 20130827105700) do | ||
80 | 80 | add_index "mountains_blogs", ["blog_id"], :name => "index_mountains_blogs_on_blog_id" |
81 | 81 | add_index "mountains_blogs", ["mountain_id"], :name => "index_mountains_blogs_on_mountain_id" |
82 | 82 | |
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 | + | |
83 | 91 | create_table "records", :force => true do |t| |
84 | 92 | t.string "mountain_id" |
85 | 93 | t.string "user_id" |
@@ -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 |
@@ -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 |