Skip to content

Commit

Permalink
squeel, adding players
Browse files Browse the repository at this point in the history
  • Loading branch information
rindek committed Jun 30, 2012
1 parent b9944f9 commit b6c3f43
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 19 deletions.
3 changes: 2 additions & 1 deletion new/rmud_webapp/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ gem 'jquery-rails'
gem 'pry'
gem 'devise'
gem 'haml'
gem 'simple_form'
gem 'simple_form'
gem 'squeel'
7 changes: 7 additions & 0 deletions new/rmud_webapp/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ GEM
multi_json (1.3.6)
mysql2 (0.3.11)
orm_adapter (0.3.0)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
pry (0.9.9.6)
coderay (~> 1.0.5)
Expand Down Expand Up @@ -107,6 +109,10 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
squeel (1.0.6)
activerecord (~> 3.0)
activesupport (~> 3.0)
polyamorous (~> 0.5.0)
thor (0.15.4)
tilt (1.3.3)
treetop (1.4.10)
Expand All @@ -132,4 +138,5 @@ DEPENDENCIES
rails (= 3.2.6)
sass-rails (~> 3.2.3)
simple_form
squeel
uglifier (>= 1.0.3)
19 changes: 19 additions & 0 deletions new/rmud_webapp/app/controllers/players_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class PlayersController < ApplicationController
before_filter :authenticate_account!

def new
@player = Player.new
@player.build_dictionary
end

def create
d = Dictionary.create(params[:player][:dictionary])
if d
p = Player.new(params[:player].except(:dictionary))
p.dictionary = d
p.account = current_account
p.save
redirect_to :root
end
end
end
5 changes: 2 additions & 3 deletions new/rmud_webapp/app/models/dictionary.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class Dictionary < ActiveRecord::Base
set_table_name "dictionary"
self.table_name = "dictionary"

attr_accessible
:nominative, :genitive, :dative, :accusative, :instrumental, :locative,
attr_accessible :nominative, :genitive, :dative, :accusative, :instrumental, :locative,
:plu_nominative, :plu_genitive, :plu_dative, :plu_accusative, :plu_instrumental, :plu_locative,
:gender_id

Expand Down
15 changes: 14 additions & 1 deletion new/rmud_webapp/app/models/gender.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
class Gender < ActiveRecord::Base
set_table_name "gender"
self.table_name = "gender"

PL_MESKI_OS = 1
PL_MESKI_NOS_ZYW = 2
PL_MESKI_NOS_NZYW = 3

PL_ZENSKI = 4

PL_NIJAKI_OS = 5
PL_NIJAKI_NOS = 6

attr_accessible :name, :description

def self.to_select_for_player
Gender.where{id.in([PL_MESKI_OS, PL_ZENSKI])}
end
end
1 change: 1 addition & 0 deletions new/rmud_webapp/app/models/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class Player < ActiveRecord::Base

belongs_to :account
belongs_to :dictionary

end
16 changes: 16 additions & 0 deletions new/rmud_webapp/app/views/accounts/my.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Moje konto

%br

= link_to "+ stwórz nową postać", new_player_path

%table
%thead
%tr
%td Imię
%td Utworzono
%tbody
- @players.each do |player|
%tr
%td= player.name
%td= player.created_at
14 changes: 0 additions & 14 deletions new/rmud_webapp/app/views/layouts/application.html.erb

This file was deleted.

10 changes: 10 additions & 0 deletions new/rmud_webapp/app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
!!!
%html
%head
%title RMUD - WebApp
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags

%body
= yield
12 changes: 12 additions & 0 deletions new/rmud_webapp/app/views/players/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
= simple_form_for @player do |f|
= f.input :name
= f.simple_fields_for @player.dictionary do |ff|
= ff.input :nominative
= ff.input :genitive
= ff.input :dative
= ff.input :accusative
= ff.input :instrumental
= ff.input :locative
= ff.input :gender_id, :as => :select, :collection => Gender.to_select_for_player, :include_blank => false

= f.submit
1 change: 1 addition & 0 deletions new/rmud_webapp/app/views/players/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render 'form'
3 changes: 3 additions & 0 deletions new/rmud_webapp/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
devise_for :accounts
match '/accounts/my', to: "accounts#my"


resources :players

root to: "accounts#my"
end

0 comments on commit b6c3f43

Please sign in to comment.