我想在我的主頁上啓動註冊過程。最後,理想情況下,該過程將遵循以下邏輯:解決兩步嵌套模型註冊過程
user = User.new
user.email = ""
user.password = ""
user.profile = Profile.new
user.profile.info = ""
user.profile.save
user.save
當然,我將使用嵌套模型表單。但是有沒有辦法將它分成兩部分?在第1部分中,User
將主要輸入user
信息以及一些profile
信息,第2部分將僅包含「配置文件」信息。然後,當所有事情都說完後,用戶會被重定向到他們的用戶配置文件。
如果這是可能的,這種類型的過程的一般思路是什麼?其次,我想知道如果有人能幫我弄清楚如何實現它。我有所有設置的嵌套模型表單,但是我的routes.rb文件/控制器中一定有一些東西搞砸了,否認了我的經驗。
這是我的routes.rb文件。
get "profiles/show"
get "/profiles/:id" => "profiles#show", :as => "profile"
post "/signup" => "profiles#create", :as => "signup"
get "skip/signup", :to => "users#newskip"
match "skip/profiles/new", :to => "profiles#newskip"
root :to => "users#new"
這裏分別是我的UsersController和ProfilesController:
*class UsersController < ApplicationController*
before_filter :authenticate, :only => [:edit, :update]
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to signup_path, :notice => 'User successfully added.'
else
render :action => 'new'
end
end
*class ProfilesController < ApplicationController*
before_filter :authenticate, :only => [:edit, :update]
def new
@user.profile = Profile.new
end
def create
@profile = Profile.new(params[:profile])
if @profile.save
redirect_to profile_path(@profile), :notice => 'User successfully added.'
else
render :action => 'new'
end
end
誰能幫我看看光明?我知道Devise是一個解決方案,但我試圖沒有這個學習。至少在一開始。這previous question/answer看起來像一個潛在的首發。
是的,謝謝。其實,它看起來像這個SO帖子只是關於我在找什麼(減去設計):http://stackoverflow.com/questions/5825135/devise-sign-up-page-as-welcome-landing-page-然後對用戶個人資料。我希望用戶在主頁上註冊,然後立即將其帶到他們的個人資料中。 – tvalent2