2012-08-19 42 views
0

我希望在我的模型不驗證顯示此錯誤顯示器使用的form_tag驗證錯誤消息在查看 - Rails的

型號:

validates_length_of :name ,:minimum => 6,:on => :create 
    validates_length_of :password ,:minimum => 6,:on => :create 

,但在我看來,這不要出現在我的觀點是

<h1>Cadastro</h1> 
    <% if flash[:note] %> 
    <%= flash[:note] %> 
    <%end%> 
    <%= error_messages_for :user %> 
    <% for erro in @user.errors.full_messages %> 
    <%= erro %> 
    <% end %> 
<%= form_tag users_path do %> 

    <%= label_tag :name %><br /> 
    <%= text_field_tag :name,params[:name] %><br /> 
    <%= label_tag :password %><br /> 
    <%= password_field_tag :password,params[:password] %> 
<%= submit_tag "Cadastrar" %> 
<%end%> 

和我的控制器如果需要的話

class SessionsController < ApplicationController 

    def new 

    end 
    def create 
     @user = User.find_by_name(params[:name]) 
    if @user && @user.authenticate(params[:name],params[:password]) 
      session[:user_id] = @user.id 
      session[:user_name] = @user.name 
      flash[:note] = 'Voce esta logado.' 
      redirect_to finances_url 
    else 
     flash[:note] = 'Falha no login.' 
     render 'new' 
    end 
    end 

感謝我的幫助非常感謝mutch

+0

啥子模式是什麼?它是用戶還是會話?如果這是一個用戶,那麼只會在用戶創建時進行驗證,而不是在登錄時進行驗證。在你的控制器中沒有創建任何模型,難怪這不起作用。 – Matzi 2012-08-19 17:09:10

+0

謝謝我解決了這個問題,在創建過程中有效。非常感謝。 – Overduka 2012-08-19 17:16:12

回答

-1

感謝我解決validing並出現在user_create絲毫驗證碼:

<% for erro in @user.errors.full_messages %> 
    <%= erro %> 
    <% end %> 
相關問題