1

我是 Rails 新手,开发第一个应用程序变得很困难,因为你知道一些事情,但你不知道如何去做。

我将我的注册表单设置在一个使用“fancy-box”jquery 弹出窗口的框中。当某些用户注册失败时,我希望页面保留在验证错误的框中,当他正确注册时,我想将他重定向到主页,但我不能这样做:

我的控制器覆盖了设计方法:

def setup
  @society = Society.new
end

# GET /resource/sign_up
def new
  super
end

# POST /resource
def create
  build_resource

  if resource.save
   if resource.active_for_authentication?
      set_flash_message :notice, :signed_up if is_navigational_format?
      sign_in(resource_name, resource)
      respond_with resource, :location => after_sign_up_path_for(resource)
    else
      set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
      expire_session_data_after_sign_in!
     respond_with resource, :location => after_inactive_sign_up_path_for(resource)
    end
  else
    clean_up_passwords resource
    render action: new  
  end
end

protected

def after_sign_up_path_for(resource)
  '/vetrina/index'  #my homepage
end

和形式:

<%= simple_form_for @society, :html => { :class => 'form-horizontal' } do |f| %>
  <fieldset>

  #all the inputs are here

  <div class="form-actions">
    <%= f.submit nil, :class => 'btn btn-primary' %>
    <%= link_to 'Cancel', "#", :class => 'btn' %>
  </div>
</fieldset>

有什么帮助吗?

4

0 回答 0