mysql,Linux,HighPerformance,ruby on Rails

2009年11月3日星期二

accepts_nested_attributes_for引起的实践

如果你读了ihower的rails best practices那个ppt,一定对39页的实践看过,我跟着实现了一下,但没有成功,对于这种失败细节,很难一下子讲清楚,如果有一个demo就好了.终于来了一份:http://github.com/anathematic/has_one_problem,clone下来后,跑起来一切ok.好了,如果你这样收手,就没有注意了,在PPT中显示的form如:<% form_for :product do |f| %>....
<% end %>
这里的是:product,但我实际中,这样是跑不了的.需要指定action.<% form_for :user, :url => {:action => 'create'} do |f| %>另外,还需要注意里面的变化: <% f.fields_for :contact_attributes do |c| %>
<%= c.label :phone,'电话' %>
<%= c.text_field :phone %>
<% end -%>
注意需要加上_attributes

参考demo:http://www.box.net/shared/vm76if7zdd


另外,增加这点tips
从Doctor Nic那里扒来的To find, clone, and fork any rubygem that is hosted on github:

$ sudo gem install drnic-github
$ gh clone --search rails
$ gh fork
To personalise the gem and share it on gemcutter:

> edit the project.gemspec to have a unique name, e.g. yourname-project
$ gem build project.gemspec
$ sudo gem install gemcutter
$ gem push yourname-project-1.0.0.gem

没有评论:

发表评论