<%= link_to 'show', :controller=>:users, :action=>:show, :id=>u.id, :confirm=>'are you sure?' %>
<%= link_to 'reset pass.', :controller=>:users, :action=>:reset_password, :id=>u.id, :confirm=>'RESET PASSWORD, are you sure?' %>
第一個鏈接工作正常,但第二個是真奇怪......有時它的工作原理,有時就是不和導致這樣的錯誤:我的link_to有什麼問題嗎?
LoadError in UsersController#index
Expected /home/anonym/Documents/RubyOnRails/authorisation/loginout/app/controllers/users_controller.rb to define UsersController
而且它不顯示確認框。無論如何,如果我刪除:確認選項不時出現第一個錯誤。
控制器:
#users_controller.rb
class UsersController < ApplicationController
...
def reset_password
@user=User.find_by_id(params[:id])
...
路線:
#routes.rb
match 'users/:id/reset_password', :to=>"users#reset_password"
這可能是可以理解的,我如果每次失敗,但它是一種隨機的。
任何想法爲什麼?
UPDATE
這在控制器稍加修改似乎來解決這個問題。
#Thread.new{UserMailer.reset_password(@user, passwd).deliver}
UserMailer.reset_password(@user, passwd).deliver
這也導致我的sqlite數據庫崩潰(如果我點擊鏈接很快幾次)。
你知道爲什麼這個線程可能是這樣一個殺手?
還有一個問題,爲什麼沒有確認框?
UPDATE
Started GET "https://stackoverflow.com/users/2/reset_password?confirm=RESET+PASSWORD%2C+are+you+sure%3F" for 127.0.0.1 at 2012-02-06 15:03:57 +0100
Processing by UsersController#reset_password as HTML
Parameters: {"confirm"=>"RESET PASSWORD, are you sure?", "id"=>"2"}
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1[0m
[1m[35mUser Load (0.4ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
[1m[36m (0.5ms)[0m [1mSELECT 1 FROM "users" WHERE ("users"."email" = '[email protected]' AND "users"."id" != 2) LIMIT 1[0m
[1m[35m (0.3ms)[0m UPDATE "users" SET "last_support_email_sent_time" = '2012-02-06 14:03:58.182567', "encrypted_password" = '5380187f533d14e2867667f8c2c9dc6671b1d930ff892a8cb4da7cdda99d01c8', "updated_at" = '2012-02-06 14:03:58.186194' WHERE "users"."id" = 2
Rendered /home/anonym/Documents/RubyOnRails/authorisation/loginout/app/views/user_mailer/reset_password.html.erb (0.2ms)
Sent mail to [email protected] (1270ms)
Date: Mon, 06 Feb 2012 15:03:58 +0100
from: User service
To: [email protected]
Message-ID: <[email protected]>
Subject: Your new password
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Hello ,</br>
Your new password is: 469ff56728
Redirected to http://localhost:3000/users
Completed 302 Found in 1407ms
Started GET "/users" for 127.0.0.1 at 2012-02-06 15:03:59 +0100
Processing by UsersController#index as HTML
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1[0m
[1m[35mUser Load (1.1ms)[0m SELECT "users".* FROM "users" ORDER BY email
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.2ms)
Rendered /home/anonym/Documents/RubyOnRails/authorisation/loginout/app/views/users/index.html.erb within layouts/application (75.8ms)
Completed 200 OK in 197ms (Views: 132.5ms | ActiveRecord: 2.6ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/loginout.css" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /loginout.css - 404 Not Found (39ms)
ActionController::RoutingError (No route matches [GET] "/assets/loginout.css"):
Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (2.1ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /jquery.js - 304 Not Modified (1ms)
Started GET "/assets/messages.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /messages.js - 304 Not Modified (1ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /application.js - 304 Not Modified (2ms)
Started GET "/assets/auth_engine.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /auth_engine.css - 304 Not Modified (2ms)
Started GET "/assets/sessions.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /sessions.css - 304 Not Modified (0ms)
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /users.css - 304 Not Modified (0ms)
Started GET "/users" for 127.0.0.1 at 2012-02-06 15:04:35 +0100
SQLite3::SQLException: unsupported file format: SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
ActiveRecord::StatementInvalid (SQLite3::SQLException: unsupported file format: SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
):
之後,數據庫損壞 - 服務器重啓沒有幫助。儘管我不再使用線程,但這種情況偶爾會發生。
您正在使用哪個版本的Rails?是3.0還是更近的?你能在發佈失敗後發佈你的development.log中包含的內容嗎? – Ryan 2012-02-04 22:28:05
@Ryan我正在使用rails 3.1.3。開發日誌添加到問題中。 – gisek 2012-02-06 14:40:29