【发布时间】:2016-09-11 10:53:26
【问题描述】:
我对 Rails 还很陌生,在用户通过条带成功付款后,我一直在努力更改数据库值。此外,付款后,它每次都会以某种方式将我重定向到不存在的“/subscriberjobs/1”。相反,它应该指向应用程序的 root_path。
这是我得到的:
路线
resources :subscriberjobs
resources :jobs
工作控制器
def new
if current_user
@job = current_user.jobs.build
else
redirect_to new_user_session_path
end
end
def create
@job = current_user.jobs.build(job_params)
if @job.save
redirect_to '/subscriberjobs/new'
else
render 'new'
end
end
Subscriberjobs 控制器(这是行不通的!)
class SubscriberjobsController < ApplicationController
before_filter :authenticate_user!
def new
end
def update
token = params[stripeToken]
customer = Stripe::Customer.create(
card: token,
plan: 1004,
email: current_user.email
)
Job.is_active = true # doesn't work
Job.is_featured = false # doesn't work
Job.stripe_id = customer.id # doesn't work
Job.save # doesn't work
redirect_to root_path # doesn't work
end
end
如果您需要更多信息,请告诉我。每个答案都非常感谢。谢谢!
【问题讨论】:
-
有什么错误吗?什么?
-
你想在这个声明中做什么? - Job.is_active.
-
@Bartek Gładys 一个错误,因为它将我引导到一个不存在的页面。这就是为什么我想重定向到 root_path。此外,我在控制台中看到
is_active仍然是假的,而不是真的 -
@vyom
is_active是 Job Model 的一个参数。 => 我创建了一个工作 => 然后我被重定向到付款,在我支付后它应该将刚刚创建的工作的is_active参数设置为true=> 然后它应该重定向到 root_pah -
@Gugubaight 我认为您应该像 object.is_active 一样访问它,为什么要像 Class.is_active 一样称呼它?
标签: ruby-on-rails ruby ruby-on-rails-4 controller rubygems