I call this js from the link:
function createNewTopLevelEntry(){ var user_id = $("#user").val(); var header = prompt("Enter the name"); $.ajax( '/users/' + user_id + '/entries', { data: { entry: { header: header, user: user_id } }, type: 'POST', cache: false, dataType: 'json', success: displayTopLevelEntries }); }
He refers to this controller:
def create @entry = Entry.new(params[:entry]) respond_to do |format| if @entry.save format.html { redirect_to @entry, notice: 'Entry was successfully created.' } format.json { render json: @entry, status: :created, location: @entry } else format.html { render action: "new" } format.json { render json: @entry.errors, status: :unprocessable_entity } end end end
This is the response on the server:
Started POST "/users/1/entries" for 127.0.0.1 at 2013-03-25 21:50:36 -0700 Processing by EntriesController#create as JSON Parameters: {"entry"=>{"header"=>"Hi", "user"=>"1"}, "user_id"=>"1"} (0.1ms) begin transaction SQL (0.5ms) INSERT INTO "entries" ("completed", "created_at", "endtime", "header", "parent", "starttime", "starttimeset", "text", "totaltime", "updated_at", "user") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["completed", nil], ["created_at", Tue, 26 Mar 2013 04:50:36 UTC +00:00], ["endtime", nil], ["header", "Hi"], ["parent", nil], ["starttime", nil], ["starttimeset", nil], ["text", nil], ["totaltime", nil], ["updated_at", Tue, 26 Mar 2013 04:50:36 UTC +00:00], ["user", "1"]] (2.5ms) commit transaction Completed 500 Internal Server Error in 10ms NoMethodError - undefined method `entry_url' for #<EntriesController:0x007fb22b9f7fd8>: (gem) actionpack-3.2.11/lib/action_dispatch/routing/polymorphic_routes.rb:129:in `polymorphic_url' (gem) actionpack-3.2.11/lib/action_dispatch/routing/url_for.rb:150:in `url_for' (gem) actionpack-3.2.11/lib/action_controller/metal/rendering.rb:60:in `_process_options' (gem) actionpack-3.2.11/lib/action_controller/metal/streaming.rb:208:in `_process_options' (gem) actionpack-3.2.11/lib/action_controller/metal/renderers.rb:34:in `block in _handle_render_options'
What is entry_url? Why is he looking for him? Do I need to include something in the model. It just has attr_accessors for vars.
class Entry < ActiveRecord::Base attr_accessible :completed, :endtime, :header, :starttime, :starttimeset, :totaltime, :user, :text, :parent end
Heres is my routes file:
Tasks::Application.routes.draw do match '/users/:id/projects' => 'users#show_projects_for_user' authenticated :user do root :to => 'home#index' end root :to => "home#index" devise_for :users resources :users do resources :entries end end
Thanks for the help.