2016-09-27 2 views
0

Ich habe eine Methode im Controller zu überprüfen, ob E-Mail bereits in der Datenbanktabelle existiert. Ich muss die Bestätigungsnachrichten unterhalb des E-Mail-Textfelds anzeigen, das dem Bild ähnlich ist und nicht flash [: error] = "メ ー 変 変 に 失敗 し ま た" "" "" ".Benutzerdefinierte Feld Validierungen Nachricht in View-Datei

Die Validierung erfolgt in der Steuerung durchgeführt, wo wir überprüfen, ob die E-Mail-Id

enter image description here

Controller-Methode:

def update_email 
    @user_login = UserLogin.find(params[:id]) 

    if @email_check = UserLogin.where(:email => params[:update_email]).first 
    redirect_to "/works?utf8=%E2%9C%93&search=&commit=%E6%A4%9C%E7%B4%A2", notice: params[:id] + 'idの メールは既に存在します!' 
    else 
     @update_email = UserLogin.where(:user_id => @user_login).update_all(:email => params[:update_email]) 

    if @update_email 
    UserLogin.where(:user_id => params[:id]).update_all(:updated_at => Time.zone.now) 
    flash[:success] = "メール変更!" 
    redirect_to works_path 
    else 
    flash[:error] = "メール変更に失敗しました!" 
    redirect_to works_path 
    end 
    end 
    end 

index.html.erb:

<%= form_for :works,:id => "email_validate", :url => {:action => 'update_email',:id => userdetails.user_id} do %> 
<td><%= email_field_tag :update_email,nil,:id =>"email",:class => "form-control" ,:placeholder =>'新しいメールアドレス。。。。', required: true %><br/></td> 
<td><%= button_to("変更", {}, {:onclick => "return confirm('メールをリセットします。よろしいでしょうか?')", :class => "btn btn-primary", :method => :update_email, :remote => true}) %></td> 
<% end %> 
+0

was ist das? Das Problem? funktioniert dein Code nicht? Gibt es einen Fehler? – mrvncaragay

+0

@mrvncaragay Der obige Code funktioniert. Aber es gibt eine "FLASH" Nachricht. Ich muss die Nachricht "メ ー ル 更 更 失敗 し ま た" "" "in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in if if if if if if if if if –

+0

also es redirect, aber der Hinweis wird nicht angezeigt? – mrvncaragay

Antwort

0
In controller: 

    flash[:notice] = 'メールは既に存在します!!' 

    redirect_to works_path 

In view: 

    <%= form_for :maintanance_works, :url => {:action => 'update_email',:id => userdetails.user_id} do %> 
     <td> 
     <%= email_field_tag :update_email, nil,:class => "form-control" ,:placeholder =>'新しいメールアドレス。。。。', required: true %><br/> 
     <p class="notice" style="color:red;font-size:12pt;"> 
     <%= flash[:notice] %></p> 
     </td> 
     <td> 
     <%= button_to("変更", {}, {:onclick => "return confirm('メールをリセットします。よろしいでしょうか?')", :class => "btn btn-primary", :method => :update_email, :remote => true}) %></td> 
    <% end %> 

**Display flash message below your textbox** 
Verwandte Themen