我想弄清楚如何使用簡單的窗體與Rails,Devise,Omniauth和Bootstrap。我有幾個問題,但其中之一是錯誤通知。簡單的窗體錯誤通知
我有一個設計登錄和註冊形式內Bootstrap模態。登記表如下。請注意,我從表格中刪除了required: true
函數,因爲我不喜歡將星號附加到標籤上(但我確實嘗試將其返回以查看錯誤通知是否可用)。
<% if user_signed_in? %>
<li>
<%= link_to('Edit registration', edit_user_registration_path) %>
</li>
<% else %>
<li>
<%= link_to 'Register', new_user_registration_path, :remote => true, 'data-toggle' => "modal", 'data-target' => "#myRModal", :method => 'get' %>
</li>
<div class="modal fade" id="myRModal" tabindex="-1" role="dialog" aria-labelledby="myRModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel" style="color:black">Register</h4>
</div>
<div class="modal-body">
<%- if devise_mapping.omniauthable? %>
<div class="facebookauth"> <%= link_to "Register with Facebook", user_omniauth_authorize_path(:facebook) %></div>
<br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<div class="linkedinauth"> <%= link_to "Register with LinkedIn", user_omniauth_authorize_path(:linkedin) %></div>
<br />
<% end -%>
</div>
<div class="modal-footer">
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs" style="padding-left:20%; text-align:left; color:black;">
<%= f.input :first_name, placeholder: 'Enter your first name', autofocus: true, :input_html => {:maxlength => 15, :size => 40} %>
<%= f.input :last_name, placeholder: 'Enter your surname', autofocus: true, :input_html => {:maxlength => 15, :size => 40} %>
<%= f.input :email, placeholder: 'Enter email', autofocus: true, :input_html => {:maxlength => 25, :size => 40} %>
<%= f.input :password, placeholder: 'At least 8 characters', :input_html => {:maxlength => 15, :size => 40} %>
<%= f.input :password_confirmation, placeholder: 'Confirm your password', :input_html => {:maxlength => 15, :size => 40} %>
</div>
<div class="form-actions" style="padding-left:20%; padding-top:5%; text-align:left; color:black;">
<%= f.button :submit, "Register" %><% end %>
我有一個用戶模式驗證電子郵件地址和密碼的存在。
我有以下命令來創建功能的用戶/ registration_controller:
def create
@user = User.new(user_params)#(params[:user])
respond_to do |format|
if @user.save
# Tell the UserMailer to send a welcome email after save
# AdminMailer.new_user_waiting_for_approval.deliver
format.html { redirect_to(root_path, notice: 'Registration received.') }
format.json { render json: root_path, status: :created, location: @user }
else
format.html { redirect_to(root_path, alert: 'Sorry! There was a problem with your registration. Please contact us to sort it out.') }
# format.html { render action: 'new' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
我有設計在我的兩個應用助手的助手,並制定幫手如下:
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
我的初始化文件有兩個簡單的表單文件。一個是simple_form.rb。另一種是simple_form_bootstrap.rb
沒有錯誤在窗體中內聯顯示。當我填寫沒有電子郵件地址的表單時,出現我的registration_controller的create函數中出現的錯誤。
當用戶點擊提交時,我真的很希望在表單中以內聯方式顯示錯誤。
有誰知道如何解決這個問題?
謝謝。
是通過AJAX提交的表單嗎? – Sharagoz