Ruby on rails 在Rails应用程序中设计Ajax注册
我正在为我的rails应用程序使用Desive,我希望通过Ajax处理注册。目前我正在跟进此事。到目前为止,用户注册工作正常(用户数据通过Ajax插入数据库),但注册后用户不会自动登录。如何实现这一点?这里有一个显示Ajax登录步骤的窗口,但我不确定是否需要它,如果需要,如何实现?这是我的密码 注册\u controller.rbRuby on rails 在Rails应用程序中设计Ajax注册,ruby-on-rails,ajax,ruby-on-rails-3,ruby-on-rails-3.1,devise,Ruby On Rails,Ajax,Ruby On Rails 3,Ruby On Rails 3.1,Devise,我正在为我的rails应用程序使用Desive,我希望通过Ajax处理注册。目前我正在跟进此事。到目前为止,用户注册工作正常(用户数据通过Ajax插入数据库),但注册后用户不会自动登录。如何实现这一点?这里有一个显示Ajax登录步骤的窗口,但我不确定是否需要它,如果需要,如何实现?这是我的密码 注册\u controller.rb class RegistrationsController < Devise::RegistrationsController def create b
class RegistrationsController < Devise::RegistrationsController
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
return render :json => {:success => true}
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
return render :json => {:success => true}
end
else
clean_up_passwords resource
return render :json => {:success => false}
end
end
# Signs in a user on sign up. You can overwrite this method in your own
# RegistrationsController.
def sign_up(resource_name, resource)
sign_in(resource_name, resource)
end
end
助手
module MyappHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
表格
<%= form_for(resource,:as=>resource_name,:url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= f.label :Username %>
<%= f.text_field :username %></p>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Sign up" %>
<% end %>
resource_name,:url=>registration_path(resource_name))do | f |%>
<%= form_for(resource,:as=>resource_name,:url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= f.label :Username %>
<%= f.text_field :username %></p>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Sign up" %>
<% end %>