Results 1 to 7 of 7
Thread: problem with form submitting
Nov 8, 2007, 20:29 #1
- Join Date
- May 2007
- 0 Post(s)
- 0 Thread(s)
problem with form submitting
Hello, I have a problem with a form that is driving me crazy
I have a 2 models Book and BookAuthor associated as below:
class BookAuthor < ActiveRecord::Base belongs_to :book ... end
class Supplier < ActiveRecord::Base has_one :author, :class_name => "BookAuthor" ... end
I'm would like to have a 3 steps process in order to submit a book: first book ID, second author ID, third publisher ID so I created these views
and the form on add_author is:
<% form_for :book_author do |form| %> <label for="book_author_first_name">first</label> <%= form.text_field :first_name%> <label for="book_author_last_name">last</label> <%= form.text_field :last_name,%> <%= submit_tag "next" %></div> <% end %>
and one controller as below:
... def add_book if session[:book].nil? @book = Book.new(params[:book]) @book.status = 0 else @book = session[:book] end if request.post? and @book.valid? @updated_book = Book.new(params[:book]) @updated_book.status = 0 session[:book] = @updated_book redirect_to :action => "add_author" end end def add_author @book = session[:book] if @book.author.nil? @author = BookAuthor.new(params[:bookAuthor]) @book.author = @author else @author = @book.author end if request.post? and @author.valid? @updated_author = BookAuthor.new(params[:bookAuthor]) @book.author = @updated_author session[:book] = @book redirect_to :action => "add_apublisher" end end
My issue is that when I submit add_author the submitted values are not inserted into @author (@author = BookAuthor.new(params[:bookAuthor])) so it is not valid.
What's wrong with my code ???
THANK YOU SO MUCH (really SO MUCH)Alla prossima ...