我一定遗漏了一些东西......我的视图正在被渲染,但看起来控制器中的代码没有被执行。我找不到问题所在。
当我单击中的登录按钮时login.html.erb
,login_process
应该调用 PublicController 的方法来对用户进行身份验证。这似乎不会发生,因为视图login_process.html.erb
只是显示,这是不可能的。
我什至尝试flash[:notice] = "heyhey"
在login_screen
操作上添加一个,以便它出现在登录表单上,但这也不会发生。
我做错了什么?里面有东西routes.rb
吗?
路线.rb
root :to => "public#index"
get "login",
:to => "public#login",
:as => "login_screen"
post "login_process",
:to => "public#login_process",
:as => "login_process"
get "logout",
:to => "public#logout",
:as => "logout"
public_controller.rb
class PublicController < ApplicationController
def login_screen
flash[:notice] = "heyhey"
end
def login_process
authenticated_user = User.authenticate params[:email], params[:password]
if authenticated_user
session[:user_id] = authenticated_user.id
session.countdown_start(1.minute)
redirect_to :public => :index
else
flash[:notice] = 'Email/Password incorrect. <a href="#">Receive a new password</a>.'
flash[:color] = "invalid"
end
render :login_screen
end
def logout
session.countdown_abort
flash[:notice] = "You are now logged out"
redirect_to :login_screen
end
def count
render :text => session.countdown_count.to_i
end
end
意见/公共/login.html.erb
<h1>Login</h1>
<p id="notice"><%= notice %></p>
<%= form_tag :login_process do %>
<div class="field">
<%= label_tag :email %><br>
<%= text_field_tag :email %>
</div>
<div class="field">
<%= label_tag :password %><br>
<%= password_field_tag :password %>
</div>
<div class="actions">
<%= submit_tag "Login" %>
</div>
<% end %>
<h1>Login</h1>
<p id="notice"><%= notice %></p>
<%= form_tag :login_process do %>
<div class="field">
<%= label_tag :email %><br>
<%= text_field_tag :email %>
</div>
<div class="field">
<%= label_tag :password %><br>
<%= password_field_tag :password %>
</div>
<div class="actions">
<%= submit_tag "Login" %>
</div>
<% end %>
login_process.html.erb
我从没想过会看到这个页面,因为用户应该被引导到其他地方
<p>login_process.html.erb</p>
<p id="notice"><%= notice %></p>
更新1:
我已将
authenticate
User 模型中的操作修改为:def authenticate(:email, :password) #x = new User #x.id = 123 return false #x end
login_process
在 PublicController 上为:def login_process if true flash[:notice] = 'boom' else flash[:notice] = 'Email/Password incorrect. <a href="#">Receive a new password</a>.' flash[:color] = "invalid" end redirect_to :login_screen end
不幸的是……同样的问题。显示
login_process.html.erb
时也没有闪烁通知。版本:
Ruby 2.0.0p247
Rails 4.0.0