1
在我正在開發的Rails 3應用程序中,我們允許用戶「激活」一個帳戶(通過輸入優惠券代碼),然後他們輸入他們的信息,並創建帳戶。Rails 3渲染動作
我遇到了一個小問題,我不清楚如何解決沒有重複的代碼(這似乎並沒有雄辯)。
這是我當前激活控制器:
class ActivationsController < ApplicationController
respond_to :html
skip_before_filter :set_client, :only => [:welcome]
def new
@user = User.new
@gc = get_group_code(params[:group_code])
if @gc.nil? || @gc.group.school_info.blank?
@countries = Country.all
@school_types = SchoolType.all
@states = State.all
else
@school_information = @gc.group.school_info
end
@user_type = UserType.find_by_type("Classroom Teacher")
end
def create
@user = User.new(params[:user].except(:custom))
if @user.save
@group = Group.find(params[:group_id])
@user.groups << @group
@user.update_mail_chimp_sponsors
UserMailer.welcome_email(@user, current_client).deliver
sign_in @user
redirect_to new_activation_welcome_path
else
render :new
end
end
def welcome
@user = current_user
end
private
def get_group_code(code = "")
group_code = GroupCode.find_by_code(code)
unless group_code.nil?
group_code.validate_code(current_client.name)
group_code
end
end
end
我遇到的問題,是對(render :new
)線31。當表單出現錯誤並且應用呈現new
方法時,新方法中的實例變量對視圖不可用。我該如何解決這個問題?