开发者

objects that are not created show on the page, and redirect fails

I tried out rails 3, and just started a new project. The following is all I typed.

rails new todo
cd todo
bundle install
rails generate scaffold Task done:boolean task:text created:date
rake db:migrate
rails server&
firefox 0.0.0:3000/tasks&

On page 0.0.0:3000/tasks/new, I filled in some values for the fields, and clicked the button to create a new task. It redirects to 0.0.0:3000/tasks with a blank page. When I manually reload the page, it shows up eight tasks even though there is supposed to be only one.

When I further click either show, edit, or destroy, it says, for e.g.: ActiveRecord::RecordNotFound in TasksController#show Couldn't find Task with ID=1.

When I reload to 0.0.0:3000/tasks, all eight tasks are still there.

What is wrong with this? Is rails corrupted on my computer?

Log

When I click 'create tasks', the terminal displays

Started GET "/tasks/new" for 127.0.0.1 at 2011-05-13 22:04:26 -0400

Processing by TasksController#new as HTML Rendered tasks/_form.html.erb (6.7ms) Rendered tasks/new.html.erb within layouts/application (25.3ms) Completed 200 OK in 35ms (Views: 27.9ms | ActiveRecord: 0.0ms)

folowed by something like this repeated eight times with x in tasks/x varying from 1 to 8:

Started POST "/tasks" for 127.0.0.1 at 2011-05-13 22:04:32 -0400 Processing by TasksController#create as HTML

Parameters: {"utf8"=>"✓", "authenticity_token"=>"QZHWWyE5KcZhLrzRhB4Fgnl9HGiQqNkn17O4CUfUUJU=", "task"=>{"done"=>"0", "task"=>"test\r\n", "created(1i)"=>"2011", "created(2i)"=>"5", "created(3i)"=>"14"}, "commit"=>"Create Task"} AREL (0.2ms) INSERT INTO "tasks" ("done", "task", "created", "created_at", "updated_at") VALUES ('f', 'test ', '2011-05-14', '2011-05-14 02:04:32.065805', '2011-05-14 02:04:32.065805') Redirected to http://0.0.0:3000/tasks/2 Completed 302 Found in 17ms [2011-05-13 22:04:32] ERROR URI::InvalidURIError: the scheme http does not accept registry par开发者_如何学Got: 0.0.0:3000 (or bad hostname?) /usr/local/lib/ruby/1.9.1/uri/generic.rb:746:in rescue in merge' /usr/local/lib/ruby/1.9.1/uri/generic.rb:743:in merge' /usr/local/lib/ruby/1.9.1/webrick/httpresponse.rb:163:in setup_header' /usr/local/lib/ruby/1.9.1/webrick/httpresponse.rb:101:in send_response' /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:86:in run' /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in block in start_thread'


You're trying to access your site using 0.0.0:3000 which is an invalid address (I'm actually surprised this even gives you access to the site at all).

Open 0.0.0.0:3000 in Firefox instead, and it will work perfectly!

(You can also use localhost:3000 or 127.0.0.1:3000)


Task is a reserved word in Rails. I guess thats the reason why rails is behaving in a starnge way.

For a list of other reserved words please refer to any of these links

http://cheat.errtheblog.com/s/rails_reserved_words/

http://www.yup.com/articles/2007/01/31/no-reservations-about-keywords-in-ruby-on-rails

http://oldwiki.rubyonrails.org/rails/pages/ReservedWords

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜