Discord
Steam
/
Developers
/
Problem with R..
Login/Join
Event Log
Problem with Ruby on Rails
0 replies, posted
Search
In This Thread
Okay im gonna make this Short. Error: [CODE]You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.save D:/Rails/rails_apps/LearningRails/app/controllers/book_controller.rb:14:in `create'[/CODE] Request: [CODE]{"commit"=>"Create", "authenticity_token"=>"qQJ0RNgsZsmk+ZM0ICs9BPeFX79usVIh93lbLDIYlok=", "book"=>{"title"=>"sadsad", "price"=>"34", "description"=>"sadfadsfdsfdsaf", "subject_id"=>"1"}}[/CODE] Controller: [CODE] def create @book == Book.new(params[:book]) if @book.save redirect_to :action => 'list' else @subjects = Subject.find(:all) render :action => 'new' end end[/CODE] View: [CODE]<h1>Add new book</h1> <% form_tag :action => 'create' do %> <p><label for="book_title">Title</label>: <%= text_field 'book', 'title' %></p> <p><label for="book_price">Price</label>: <%= text_field 'book', 'price' %></p> <p><label for="book_subject">Subject</label>: <%= collection_select(:book,:subject_id,@subjects,:id,:name) %></p> <p><label for="book_description">Description</label><br/> <%= text_area 'book', 'description' %></p> <%= submit_tag "Create" %> <% end %> <%= link_to 'Back', {:action => 'list'} %>[/CODE] Thanks in advance. [editline]06:10PM[/editline] Fixed it. Accidentally typed: @book == Book.new(params[:book])
Sorry, you need to
Log In
to post a reply to this thread.