2014-01-14 26 views
0

這裏列是我的新手故事,Ruby的Rails的更新兩個不同的表使用形式

我的表看起來像這樣:

create_table "books", :force => true do |t| 
    t.string "title" 
    t.integer "count" 
    t.integer "id" 
    end 

    create_table "users", :force => true do |t| 
    t.string "name" 
    t.decimal "money" 
    end 

用戶可以創建許多書籍,用戶使用這些表單進行更新:

更新錢:

<%= form_for(@user) do |f| %> 
    <%= f.number_field :money, :value => @user.money %> 
<% end %> 

更新書名,計數等,每個書:

<% @book.each do |book| %> 
    <%= form_for(book) do |f| %> 
     <%= f.number_field :count %> 
     <%= f.text_field :title %> 
    <% end %> 
<% end %> 

而我試圖做的是我想更新他們兩個。 (可以說用戶需要更新的金錢和書名),目前它只能更新錢或圖書信息分別

型號:

class Book < ActiveRecord::Base 
    attr_accessible :count, :title, :id 
    belongs_to :user 
end 

什麼想法?謝謝!

回答

相關問題