在用户通过条带成功付款后,我对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 Controller(这是不起作用的!)
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
如果您需要其他信息,请告诉我。每个答案都非常感谢。谢谢!
答案 0 :(得分:1)
将已保存的职位ID作为参数发送给subscriberjobs / new。您可以保留隐藏字段,该字段将在subscriberjobs / new html表单中具有值job_id,这将调用您的SubscriberjobsController #update方法。可以使用params访问它。
在JobController中#create
redirect_to "/subscriberjobs/new?job_id=#{@job.id}"
在SubScribeJob表格中
hidden_field_tag 'job_id', params[:job_id]
在您的SubScribeJobCotroller
中@job = Job.find(params[:job_id])