简体   繁体   English

Rails 4错误:ActiveRecord :: RecordNotFound找不到'id'

[英]Rails 4 Error: ActiveRecord::RecordNotFound Couldn't find 'id'

I'm fairly new to rails and struggling on changing database values after the user successfully paid via stripe. 在用户成功通过条带付款后,我对rails非常陌生并且在改变数据库值方面苦苦挣扎。 Additionally after paying, it somehow redirects me everytime to '/subscriberjobs/1' where the following error appears. 此外,付款后,它会以某种方式将我每次重定向到'/ subscriberjobs / 1',其中出现以下错误。 Instead it should direct to the root_path of the application. 相反,它应该指向应用程序的root_path。

This is the appearing error: 这是出现的错误:

ActiveRecord::RecordNotFound in SubscriberjobsController#update
Couldn't find Job with 'id'=

Here is what I've got: 这是我得到的:

Routes 路线

resources :subscriberjobs
resources :jobs

Jobs Controller 工作控制器

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?job_id=#{@job.id}"
  else
    render 'new'
  end
end

Subscriberjobs Controller (Here is what doesn't work!) Subscriberjobs控制器(这是什么不起作用!)

class SubscriberjobsController < ApplicationController

    before_filter :authenticate_user!

    def new
    end

    def update

        @job = Job.find(params[:job_id])

        token = params[stripeToken]

        customer = Stripe::Customer.create(
            card: token,
            plan: 1004,
            email: current_user.email
            )

        @job.is_active = true
        @job.is_featured = false
        @job.stripe_id = customer.id
        @job.save

        redirect_to root_path

    end
end

Form 形成

= simple_form_for @job do |f|
    = f.input :company, required: true
    = f.input :title, required: true
    = f.input :job_filename
    = f.input :location, required: true
    = f.input :sort
    = f.input :tag_list, required: true
    = f.input :content_one
    = f.input :content_two
    = f.input :content_three
    = f.hidden_field :job_id, value: params[:id]
    = f.button :submit

Please tell me if you need additional information. 如果您需要其他信息,请告诉我。 Every answer is very appreciated. 每个答案都非常感谢。 Thanks! 谢谢!

Your problem is here: 你的问题在这里:

@job = Job.find(params[:job_id])

It looks, params[:job_id] is equal nil . 看起来,params [:job_id] nil Maybe your params job_id is called something different, for example [:id] ? 也许你的params job_id被称为不同的东西,例如[:id]

Other question is, why you updating Job in SubscriberJobsController ? 其他问题是,为什么要在SubscriberJobsController更新Job Maybe will be bether if you use JobsController to do this ? 如果您使用JobsController执行此操作,也许会更好?

Try params[:job][:id] . 尝试params[:job][:id] Use View Source in the browser or eg Chrome dev tools to check how the form is rendered as it will tell you the parameters are being set. 使用浏览器中的“查看源”或Chrome浏览器工具来检查表单的呈现方式,因为它会告诉您正在设置的参数。 Also, watch the Rails log when you submit the form - you'll see what parameters are submitted. 此外,在提交表单时,请查看Rails日志 - 您将看到提交的参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails 4错误:ActiveRecord :: RecordNotFound找不到&#39;id&#39;= - Rails 4 Error: ActiveRecord::RecordNotFound Couldn't find 'id'= Rails 4错误:ActiveRecord :: RecordNotFound找不到id = - Rails 4 Error: ActiveRecord::RecordNotFound Couldn't find id= Rails 4错误:ActiveRecord :: RecordNotFound /找不到&#39;id&#39;= - Rails 4 Error: ActiveRecord::RecordNotFound / Couldn't find 'id'= ActiveRecord :: RecordNotFound-在Rails中找不到ID =的用户 - ActiveRecord::RecordNotFound - Couldn't find User with id= in Rails Rails-ActiveRecord :: RecordNotFound(找不到带有&#39;id&#39;= 27的评论): - Rails - ActiveRecord::RecordNotFound (Couldn't find Comment with 'id'=27): Rails:ActiveRecord::RecordNotFound 找不到没有 ID 的照片 - Rails: ActiveRecord::RecordNotFound Couldn't find Photo without an ID Rails:ActiveRecord :: RecordNotFound-在没有ID的情况下找不到用户 - Rails: ActiveRecord::RecordNotFound - Couldn't find User without an ID Rails:“找不到带有&#39;id&#39;=&#39;的电影”(ActiveRecord :: RecordNotFound) - Rails: “Couldn't find Movie with 'id'=” (ActiveRecord::RecordNotFound) 错误ActiveRecord :: RecordNotFound(在没有ID的情况下找不到Planner): - Error ActiveRecord::RecordNotFound (Couldn't find Planner without an ID): Ruby日志中的错误-&gt; ActiveRecord :: RecordNotFound(找不到&#39;id&#39;= 1的计划): - Error in Ruby logs -> ActiveRecord::RecordNotFound (Couldn't find Plan with 'id'=1):
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM