Ȥ Blog

Ruby,C#

RubyOnRails

Rails: fixture:loadno(ʥСΰաˤȤ̾

Rails

rake db:fixtures:load

¹Ԥ

PGError: ERROR: column "false" of relation xxxxx

⤽"false" ʤƤϤʤɡ

ǡFixtureȤǧƤߤ
noʥʥСȤ̣Ǥ̾ˤΤȻפޤˤȤ̾ȯ
fixutureϤʴ

id: 1
name: satoyan
no: 
job: 
....

Ĥ򤷤Ƥ褦Ǥ
ȤäƤDBPostgresqlʤΤǤbooleanΥФơno, 0, false, fȤƥ false ΰդˤʤ褦ǡɤRailsnoȤʸ̾ʤΤˤؤ餺falseȤʸ֤ƤƤޤä褦Ǥ

ȸȤ no 餿 "no" Ȥ뤳ȤDz衣
ǽ顢֤Ϥ  falseʤ󤢤櫓͡פȤäƤФ餯𤷤Ƥޤޤ


redmine GmailȤ

redmine ΩƤ뤳ȤˤʤäΤǤ᡼gmailȤ
ǡϤɤ ȤȤĴ٤redmineΥɤ˽񤤤Ƥޤ

http://redmineblog.com/articles/setup-redmine-to-send-email-using-gmail/

action_mailer_optional_tls.git

RailsgmailϤȤϤäΤǤredmineϥ᡼ȼyamlǴƤ餷ɤ񤯤ȤϰȻפäƤΤǤ

action_mailer_optional_tls.git

ȤRailsΥץ饰ɬפˤʤޤ
ޤϰʤǤ
 
 

capistrano svn+ssh

SubversinoؤΥsvnhttpǤϤʤsvn+sshץȥѤƤ硢ɤCapistranoääƤʤ
deploy.rb褫SVNСؤsshΥѥɤꤹˡʤ顢Τ褦ʤΤǤ

ǧڤˤơssh-agentΩƤ뤫ѥɤʤθեˤΤñʤΤǤ礦äȡ

eval `ssh-agent` 

ǥȤư

ssh-add ե

եϿƤOKΤ褦
agent餹

eval `ssh-agent -k`

ޤ

ssh-agent bash(ȤzshȤ

äƤȡХå饦ɤǵư³ơλȼʬ⽪λƤ褦Ǥ

Ǥ⡢ɤäݤʤΤǡѥɤʤθեˤƤߤ롣

Ǥ˸եȤäƤΤǡ

ssh-keygen -p

ǥѥѹơ̵

cap depoy

ェλ
 
ޤ sshsvnäƤʤΤʡ
ǧڶΩƤơSSLHTTPñȻפ

 

WindowsRailsȯ ٤

WindowsRailsȯȤ˻䤬֤äꡣ

  • Railsεư٤(20ä餤ˡϥƥȶưȯˤƤ̿ŪʥԡɤǤƥȼ¹Ԥ٤20Ԥ櫓Ǥ顣
  • WindowsΥޥɥץץȤʸɤSJISɡRailsϴUTF8ʤΤ RSpecΥƥȼ¹Ի˥åʸΤǡ¨¤˥åǧǤʤޥɥץץȤʸɤѹRSpecԶ礬ȯ褦ʡ
  • ƱWindowsLinuxΥޥɥץץȤǤϻȤ˱ťκ롣֡/ե˼¹°Ĥʤᡢ Ƭ ruby ǤĤʤʤɡ
  • gemʤɤǸƤʥ饤֥ꡢġ뤬WindowsбƤʤΤ롣ǥץġCapistranoȤʤ̿Ū
  • ǥTextMateȤʤeTextEditorϤΤǤTextMateΤ褦ˤϤʤviϷ
¾ˤ⤢뤫⤷ޤ󤬡Ȥꤢ˻פ⤫֤ΤϤʤȤǤ
ȤƤϡWindowsRailsγȯ٤ǤϤʤȤȤˤʤΤǤºݤθǤϤ櫓ˤԤޤ
ʤΤǡϡ
  • ǥ: TextMateeTextEditorEclipseNetBeansʤɤIDERailsǤϥǥåȤΤۤ¿
  • ¹ԴĶ: cygwinRailsĶۡߥʥ륽եȤPoderosa
  • ư٤: ʤȤƤƥȻλ֤ûΤSpecServerΩƤ롣gemsporkȤΤѤäƤޤäƤ롣
DzȤʤ˳ȯƤޤ
Ǥ⡢eTextEditorRSpecХɥǤΥեʥӥ˵ǽʤäꡢsporkΩƤƤ ./script/generate ʤɡrspecʳRailsưѤ餺٤ʤɡԹϤޤ
 
ȡºݤˤäƤΤǤǥWindowseTextEditorȤΤƱǤºݤRailsĶLinux˹ۤơFTP⤷Sambaǥե˥ƥԽߤʤȤäƤޤȡǥΥեʥӥǽʤFTPˡͤ˻֤Samba)ǡ˲ˤϻޤǤ
ǥVIǤȤͤʤ餤Ǥ礦ɡäѤTextmateǺꤿǤ顢 IDEϤͤRailsǤɬʬʤ

ActiveRecord ֥ơ֥ѤΥ

⤤Ĥ˺ƤޤΤǤ
ȤСȤ֥ӥ
Member :
Article : ֥
ȤĤΥǥ뤬ꡢ
ˤǤеȤ˲ϢդơεΡɼԡפȤǥǡȻפäϡ֥ơ֥ѤȻפΤǤRailsξϤʴǤޤ
 
֥ơ֥ΥǥȤơArticlesMember ǥޤ
̤̾Ϥ줸ʤƤ⤤ΤǤRailsε˽äƤޤ
 
ŪˤĤMemberArticleID֥ơ֥Ǥ
֥ơ֥Τ˿ǥɬפΤ Ȼפ⤷ޤ󤬡㤨СФɼԤɾʤ褯ޡߤʥġˤȤ¾°ʤ륱褯ȻפޤȤäѤǥȤƻΤȻפޤ
 
줾Υǥ¿ʬʴ
has_manythroughȤޤ 
# ɼԤϲȵ°Ƥ
class ArticlesMember < ActiveRecord
  belongs_to :member
  belongs_to :article
end

#֥ơ֥ readers(Readerǥ)̤ɼԤˤʤäƤ뵭(ArticleǥˤäƤ
class Member < ActiveRecord
  has_many :articles_members
  has_many :articles, :through => :articles_members, 
end

# Ʊ ֥ơ֥ articles_members(ArticlesMemberǥ̤Ʋǡ(MemberǥˤäƤ
class Article < ActiveRecord
  has_many :articles_members
  has_many :members, :through => :articles_members
end
Ǵñ˵ǡɼԤȤƤβ˥ޤ ʴ
# Ȥ뵭ɼԤΥե͡ɽ
article = Article.find(1)
article.members.each do |member|
  p "εɼԤ #{member.full_name} Ǥ"
end
article.members Ȥ̾ɼԾ˥Ƥޤñɼ==Memberǥ顢members Ȥ̾ˤʤäƤǤ äľŪ readers(ɼԤʤ)Ȥϡ source ץѤOKǤ
class Article < ActiveRecord
  has_many :articles_members
  has_many :readers, :through => :articles_members, :source => :member
end

#ȡƱ褦ˡ

article = Article.find(1)
article.readers.each do |reader|
  p "εɼԤ #{reader.full_name} Ǥ"
end
ʴˤʤޤ
⤦˺ʤǤ硣 

RailsǥͥȤǥformȤ: fields_for, accepts_nested_attributes_for

⡢ɤä ȤʤäƤޤĤ˺ƤޤΤǡ񤤤Ȥ

RailsǤ form_for ӥ塼إѡѤСΥǥHTMLեǤȡPOST줿ǡǥ˳ڤˤʤޤ
 
def create_member
  m = Member.create(
    :email => params[:email], 
    :job => params[:job], 
    :sex => params[:sex])
end
ʽ
def create_member
  m = Member.create(params[:member])
end
ǺѤǤޤޤ
ޤޤǤ̤ʤΤǤ㤨Memberν̤ΥǥƤϤɤä ȸ¿ͭꡢ˺ƤΤĴľƤޤ

ޤǥ accepts_nested_attributes ޤ
ʤȥͥȤ°äƤʤ褦ǤξMemberǥ뤬AddressǥäƤΤǡMemberǥ륯饹
accepts_nested_attributes_for :address, :allow_destroy => true
ơ
ӥ塼ϡ
<% form_for @member do |f| %>
  email: <%= f.text_field :email %> <br/>
  job: <%= f.text_field :job %> <br/>
  sex: <%= f.text_field :sex %>
  <!-- ͥȤ -->
  <% f.fields_for :address do |f2| %>
    ƻܸ: <%= f2.text_fieldf :prefecture %>
    Į¼: <%= f2.tet_field :city %>
    .....ʴ
  <% end %>
<% end %>
fields_for Ȥɤ櫓Ǥ͡

ΤʤȤϡform_forϻѤˡեɽ񤤤ơȥ顼ǤĤꤷƤޤ
 

ʣСRuby˻ͤRVM

RVMȤʣСRubyδ򤷤ƤȤߤȸȤRails3Υ꡼󥭥㥹ȤΤäΤǡ桹ˤʤʤä1.9Ϥ򥤥󥹥ȡ뤷Ƥߤޤ

RVMΥ
http://rvm.beginrescueend.com/

ɥȤ򸫤ʣΥ󥹥ȡˡ褦ǤGit侩Τ褦ʤΤGitǥ󥹥ȡ롣
http://rvm.beginrescueend.com/rvm/install/

mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm -rf ./rvm/ && git clone --depth 1 git://github.com/wayneeseguin/rvm.git && cd rvm && ./install

BootstrapScriptƤʤΤѰդƤơ򤽤ΤޤޥߥʥŽĤȡ
Git, Rvm, Ruby1.8.6,1.8.7,ree,1.9.1,jruby,rbx 쵤˥󥹥ȡ뤷Ƥ褦ǤäƤޤ󤬡reeäƲ

ǡRubyΥ󥹥ȡ롣
rvm install 1.9.1 
ǤդΥСRuby󥹥ȡ뤬ǽʤ褦Ǥ

rvm listȤȤʴˤʤޤ
02


system [ x86_64] äƤΤϡ̤˼ʬǥ饳ѥ뤷ƥ󥹥ȡѤߤäRubyΤȤǤ

ǥСڤؤˤϡ
rvm 1.9.1
ȤOKǤ
13

ڤؤΥС 1.8.7 ǡ
ڤؤ 1.9.1ˤʤäƤΤ狼뤫Ȼפޤ

ڤؤRubyϤޤǸߤΥߥʥΥåδ֤ͭʤΤǡ˥ߥʥ볫ȡޤRuby1.8.7ޤΥСꤷϡ--default ץꤹ褦Ǥ

rvm 1.9.1 --default

ȤRuby1.9.1ư褦Ǥ
ǡȤäƤRubyᤷϡ
rvm system --default Ȥиޤ
48


 gemΩƤΤǡ
.rvm/rubies/ruby-1.9.1-p378/bin/gem
ɬפʤΤ٥󥹥ȡ뤷ޤ
ȤꤢRails3äƤߤ褦ʡ
 

TextMateRSpec¹

RSpecϤĤ⥿ߥʥǥޥáƤäƤΤǤRSpecɤTextMatedz֤ǡޤä Command + R 򲡤Ƥޤä顢ƥȤϤHTMLեޥåȤǷ̤ɽޤ
ʴ
̤˻ŪʳȯʤΤǥƥƤƤ⹽ޤ
55

⤷ʤ
ʤϡ./script/spec -cfs <target_file or directory>
ȤäƤΤǤϤǤ⤷ޤ
ˡcontrol + shift + ↓ RSpecեȤΥƥоݤΥե(controller,mode,etc)ԤǤޤ⤫ʤꤤǤ͡
shift + alt + command + ↓
SpecбƤʤΤǽǤ

ʤߤ control + shift + R Rake¹ԤǤޤ
β̤ǥθȤäʤΤǤ
05

content_for ǥǥեȤꤹ

ڡmetaΥɤʤɤѹʤɤϡcontent_for ǤǤƤΥӥ塼ǤꤹΤݤ顢content_forѰդƤ󥰤ơѰդƤʤеΤΤѤ
ǡɤΤʡȻפĤ⤪äˤʤAPIӥ塼
http://apidock.com/rails
Ĵ٤顢ñifʸǤΤǤ͡
    1     <% if yield :meta_keywords %>
2 <%= yield :meta_keywords %>
3 <% else %>
4 <meta name="keywords" content="ϵΥ" />
5 <% end %>
6

    1 
2 <% content_for :meta_keywords do %>
3 <meta name="keywords" content="hoge" />
4 <% end %>
5
6

ȯƤޤäΤǤ
content_for äʣꤷ顢ñɵƤΤǤ͡


    1 
2 <%= yield :test %>
3
4 <% content_for :test do %>
5 hello
6 <% end %>
7 <% content_for :test do %>
8 world
9 <% end %>

Ȥ顢ñ hello worldɽޤ

i18n localeեƤ gem plugin

Rails2.2(ä褦ʡˤi18nбȸȤǡޤǤϾ˱ѸɽƤʥåñܸ첽Ǥ褦ˤʤä褦ǡ
config/locales/
en.ymlȤ
ja.ymlȤФȤΤȡ
ǡդưŪˤäƤץ饰󤬤ޤ
⡢ǥ°̾ȤƤȸͥΤǤ
줿Τ򥶡ȸƤäơʬľкѤ櫓Ǥ顢鼫ʬǽ񤯤Τ٤СʤڤǤ

ȤϤ
http://github.com/amatsuda/i18n_generators

󥹥ȡ
sudo gem install amatsuda-i18n_generators

./script/generate i18n_locale ja
Ȥȡʴǡconfig/locales/ja.yml ޤ

# Japanese translations for Ruby on Rails
# by Akira Matsuda (ronnie@dio.jp)
# AR error messages are basically taken from Ruby-GetText-Package. Thanks to Masao Mutoh.

ja:
date:
formats:
default: "%Y/%m/%d"
short: "%m/%d"
long: "%Yǯ%m%d (%a)"

day_names: [, , , , , , ]
abbr_day_names: [, , , , , , ]

month_names: [~, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
abbr_month_names: [~, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

order: [:year, :month, :day]

time:
formats:
default: "%Y/%m/%d %H:%M:%S"
short: "%y/%m/%d %H:%M"
long: "%Yǯ%m%d(%a) %H%Mʬ%S %Z"
am: ""
pm: ""



ˡ
./script/generate i18n_translation ja
Ȥȡǥ°̾Ƥޤ

      member: 
pkid: "Pkid" #g
user_name: "桼̾" #g
application_name: "ץꥱ̾" #g
email: "E᡼" #g
comment: "" #g
password: "ѥ" #g
password_question: "ѥɤμ" #g
password_answer: "ѥɤβ" #g
is_approved: "ǧ" #g

־ǧפäƤΤϤΤľ
ץե

Ȥ

C#ɻŻRubyФʳȯԡ
ǶDockerȤؿȤAngularJS˥ϥޤäƤ롣
¢ȤĮȤȤ˽ס

QR
QR
  • 饤֥ɥ֥