2011-09-01 2 views
0

내 홈페이지에서 가입 절차를 시작하고 싶습니다. 결국이 프로세스는 이상적으로 다음 논리를 따릅니다.2 단계 중첩 모델 가입 절차 문제 해결

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 파일입니다.

*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 

사람이 나에게 빛을 보여 도울 수있다 : 여기

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입니까? 나는 Devise가 해결책 인 것을 안다. 그러나 나는 그것없이 배우려고 노력하고있다. 적어도 처음에는 이 previous question/answer은 잠재적 인 시동기처럼 보입니다.

답변

0

user 및 을 홈페이지에 작성하여 완료했습니다. 두 번째 단계로 프로필 # redirect_to 프로필로 편집하십시오.

0

Here은 다단계 양식에 대한 Railscast입니다. 나는 그것이 당신이 성취하려는 것을 위해 당신을 궤도에 올려 놓아야한다고 생각합니다.

+0

예, 감사합니다. 사실, 그것은 그래서 내가 찾고있는 건 (Devus 빼기) 게시물입니다 : http://stackoverflow.com/questions/5825135/devise-sign-up-page-as-welcome-landing-page- 그 다음에 사용자 프로파일. 사용자가 홈페이지에 가입 한 후 즉시 프로필로 연결되기를 바랍니다. – tvalent2