test
test

Reputation: 2466

Ruby Rails update two different table columns using form

Here is my newbie story,

my table looks like this:

  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

user can create many books, and user using these forms to update it:

to update money:

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

to update book title, count etc., for each books:

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

and im trying to do is i want update both of them. (lets say user need to update money and book title) currently it only able to update money or book info separately

model:

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

any idea? Thanks!

Upvotes: 0

Views: 935

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176352

It's not that simple to explain in a single answer. I suggest you to have a look at the following Railscasts to get an idea.

Upvotes: 1

Related Questions