1
錯誤在Rails教程(Hartl)v3.2錯誤(RoR教程)-dropdown不啓動w/bootstrap-會話銷燬路徑不正確?
我在第8章,所有測試都在練習之前正確通過。除了兩個問題(我認爲他們是相關的)。
由於會話銷燬路徑看起來不正確,因此下拉菜單沒有使用引導程序觸發。我也嘗試使用的form_tag到位的form_for標記的和我不斷收到以下錯誤:
undefined method `[]' for nil:NilClass
這是在應用程序/視圖/會話new_html.erb:
<% provide(:title, "Sign in") %>
<h1>Sign in</h1>
<div class="row">
<div class="span6 offset3">
<%= form_tag sessions_path do %>
<%= label_tag :email %>
<%= text_field_tag :email %>
<%= label_tag :password %>
<%= password_field_tag :password %>
<%= submit_tag "Sign in", :class => "btn btn-large btn-primary" %>
<% end %>
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>
這裏的sessions_controller.rb:
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_email(params[:session][:email])
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_to user
else
flash.now[:error] = 'Invalid email/password combination' # Not quite right!
render 'new'
end
end
def destroy
sign_out
redirect_to root_path
end
end
最後,這裏的耙路輸出:
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
signup /signup(.:format) users#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
help /help(.:format) static_pages#help
about /about(.:format) static_pages#about
contact /contact(.:format) static_pages#contact
root / static_pages#home
任何幫助將是偉大的。
編輯:
cbright擁有它。我不得不修改sessions_controller。以下兩行按預期工作。
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
這樣做的竅門,謝謝!用正確的代碼更新原始問題。 – 2012-03-21 01:18:28