我有一个users_controller
create
看起来像这样的方法:
def create
@user = User.new(user_params)
@user.update_auth_token = true
@user.mark_as_read_confirmation = 1
@user.hide_tagged_feeds = 1
coupon_valid = false
if user_params['coupon_code']
coupon = Coupon.find_by_coupon_code(user_params['coupon_code'])
coupon_valid = (coupon.present? && !coupon.redeemed)
end
if coupon_valid || !ENV['STRIPE_API_KEY']
@user.free_ok = true
end
if params[:user] && params[:user][:password]
@user.password_confirmation = params[:user][:password]
end
if @user.save
unless @user.plan.stripe_id == 'free'
deactivate_subscriptions = Feedbin::Application.config.trial_days + 6
send_notice = Feedbin::Application.config.trial_days - 1
TrialDeactivateSubscriptions.perform_in(deactivate_subscriptions.days, @user.id)
TrialSendExpiration.perform_in(send_notice.days, @user.id)
TrialEnd.perform_in(Feedbin::Application.config.trial_days.days, @user.id)
end
@analytics_event = {eventCategory: 'customer', eventAction: 'new', eventLabel: 'trial', eventValue: 0}
flash[:analytics_event] = render_to_string(partial: "shared/analytics_event").html_safe
sign_in @user
redirect_to root_url
else
render "new"
end
end
我将一些用户数据和其他与模型无关的数据发布到users_controller
. 我的问题是如何调用 create 方法并根据我准备的会话变量设置 user_params ?