我有一个应该呈现错误消息的表单,但我不确定如何呈现错误消息,因为单击按钮后我的表单正在使用 Javascript 显示。我正在使用设计进行注册,它只是不显示错误消息。我正在使用 Rails 4。
这是单击后隐藏注册按钮并显示表单的代码:
<script type="text/javascript">
$(function() {
$('#prelaunchbutton').click(function() {
$('#prelaunchregistrationbutton').fadeToggle('slow');
$('.prelaunchhide').fadeToggle('slow');
return false;
});
});
</script>
这是设计登记表(为简洁而缩短):
<div class="prelaunch_preregisterbutton" id="prelaunchregistrationbutton">
<%= link_to image_tag("pre-register.png", :border=>0), '#', id:'prelaunchbutton' %>
</div>
<div class="span10 offset1 prelaunchhide">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :class => "form-inline") do |f| %>
...
<% end %>
</div>
这是设计注册控制器:
class RegistrationsController < Devise::RegistrationsController
before_filter :authenticate_user!
respond_to :html, :json
def new
end
def create
@user = User.new(user_params)
@user.build_store(store_params)
if @user.save
UserMailer.preregister_confirmation(@user).deliver
sign_in @user
redirect_to prelaunch_gear_path, :flash => {:success => "Welcome"}
else
render root_path
end
end
...
protected
def after_update_path_for(resource)
user_path(resource)
end
private
def user_params
params.require(:user).permit(:firstname, :lastname, :email, :password)
end
def store_params
params.require(:store).permit(:storename)
end
end