Ruby on rails ActionController::作业控制器更新中缺少参数(缺少参数或值为空:作业)
每当我试图使用“Payloa Stripe payment Processor Integration”为我的应用程序上的招聘广告付款时,我就会出现此错误 缺少参数或值为空:作业 在此之前,我解释了我认为可能导致错误的原因,以下是我的代码 开发日志Ruby on rails ActionController::作业控制器更新中缺少参数(缺少参数或值为空:作业),ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,每当我试图使用“Payloa Stripe payment Processor Integration”为我的应用程序上的招聘广告付款时,我就会出现此错误 缺少参数或值为空:作业 在此之前,我解释了我认为可能导致错误的原因,以下是我的代码 开发日志 ActionController::ParameterMissing (param is missing or the value is empty: job): app/controllers/jobs_controller.rb:53:in
ActionController::ParameterMissing (param is missing or the value is empty: job):
app/controllers/jobs_controller.rb:53:in `job_params'
app/controllers/jobs_controller.rb:19:in `update'
jobs\u controller.rb
class JobsController < ApplicationController
def index
@jobs = Job.paid_ad
end
def show
@job = Job.find(params[:id])
end
def edit
@job = Job.find(params[:id])
redirect_to @job if @job.paid?
end
def update
@job = Job.find(params[:id])
if !(@job.paid?)
@job.update_attributes(stripeEmail: params[:stripeEmail], payola_sale_guid: params[:payola_sale_guid])
@job.update(job_params) unless @job.paid?
redirect_to show_job_path(@job)
else
render :edit
end
end
def new
@job = Job.new
end
def create
@job = Job.new(job_params)
if @job.save
redirect_to preview_job_path(@job)
else
render :new
end
end
def preview
@job = Job.find(params[:id])
redirect_to @job if @job.paid?
end
def payment
@job = Job.find_by_permalink(params[:permalink])
redirect_to job_path(@job) if @job.paid?
end
private
def job_params
params.require(:job).permit(:title, :category, :location, :description, :to_apply, :email, :company_name, :website)
end
end
class Job < ActiveRecord::Base
include Payola::Sellable
validates :title,
:category,
:location,
:description,
:company_name,
:website,
:email,
:to_apply,
presence: true
validates :title, length: { maximum: 75 }
validates :description, length: { minimum: 300 }
validates :to_apply, length: { maximum: 500 }
validates_formatting_of :email, using: :email
validates_formatting_of :website, using: :url
before_validation :provide_name, :provide_permalink
def self.paid_ad
where.not('stripeEmail' => nil).where.not('payola_sale_guid' => nil).where('created_at > ?', 30.days.ago)
end
def paid?
(!(self.stripeEmail == nil) && !(self.payola_sale_guid == nil))
end
private
def provide_name
self.name = 'FarFlung' if self.name == nil
end
def provide_permalink
self.permalink = "#{ self.name } #{ SecureRandom.hex }".parameterize if self.permalink == nil
end
end
<%= render 'shared/four_breaks' %>
<div class="container-fluid">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<strong style="font-weight: bold; font-size:20px;">STEP 3 (OF 3): ENTER YOUR PAYMENT INFORMATION</strong>
<%= render 'shared/two_breaks' %>
<div class="lg-4 col-lg-offset-4">
<%= simple_form_for @job,
html5: {
class: 'payola-payment-form',
'data-payola-base-path' => main_app.payola_path,
'data-payola-product' => @job.product_class,
'data-payola-permalink' => @job.permalink
} do |f| %>
<p style="color:red"><span class="payola-payment-error"></span></p>
<div class="row">
<div class="col-lg-12">
<label>Your email address
<input type="email" name="job[stripeEmail]" data-payola="email" value="<%= @job.email %>" />
</label>
</div>
<div class="col-lg-12">
<label>Card number
<input type="text" data-stripe="number" />
</label>
</div>
<div class="col-lg-4">
<label>Exp Month
<input type="text" data-stripe="exp_month"/>
</label>
</div>
<div class="col-lg-4">
<label>Exp Year
<input type="text" data-stripe="exp_year"/>
</label>
</div>
<div class="col-lg-4">
<p><label>CVC Code
<input type="text" data-stripe="cvc"/>
</label></p>
</div>
<div class="col-lg-12">
<%= f.submit 'PAY AND DISPLAY AD NOW', class: 'button radius medium expand success' %>
</div>
</div>
<% end %>
<%= render 'shared/two_breaks' %>
<%= link_to (image_tag('big.png')) %>
<%= render 'shared/four_breaks' %>
</div>
</div>
</div>
</div>
类作业控制器
我还在模型中定义了一个方法
job.rb
class JobsController < ApplicationController
def index
@jobs = Job.paid_ad
end
def show
@job = Job.find(params[:id])
end
def edit
@job = Job.find(params[:id])
redirect_to @job if @job.paid?
end
def update
@job = Job.find(params[:id])
if !(@job.paid?)
@job.update_attributes(stripeEmail: params[:stripeEmail], payola_sale_guid: params[:payola_sale_guid])
@job.update(job_params) unless @job.paid?
redirect_to show_job_path(@job)
else
render :edit
end
end
def new
@job = Job.new
end
def create
@job = Job.new(job_params)
if @job.save
redirect_to preview_job_path(@job)
else
render :new
end
end
def preview
@job = Job.find(params[:id])
redirect_to @job if @job.paid?
end
def payment
@job = Job.find_by_permalink(params[:permalink])
redirect_to job_path(@job) if @job.paid?
end
private
def job_params
params.require(:job).permit(:title, :category, :location, :description, :to_apply, :email, :company_name, :website)
end
end
class Job < ActiveRecord::Base
include Payola::Sellable
validates :title,
:category,
:location,
:description,
:company_name,
:website,
:email,
:to_apply,
presence: true
validates :title, length: { maximum: 75 }
validates :description, length: { minimum: 300 }
validates :to_apply, length: { maximum: 500 }
validates_formatting_of :email, using: :email
validates_formatting_of :website, using: :url
before_validation :provide_name, :provide_permalink
def self.paid_ad
where.not('stripeEmail' => nil).where.not('payola_sale_guid' => nil).where('created_at > ?', 30.days.ago)
end
def paid?
(!(self.stripeEmail == nil) && !(self.payola_sale_guid == nil))
end
private
def provide_name
self.name = 'FarFlung' if self.name == nil
end
def provide_permalink
self.permalink = "#{ self.name } #{ SecureRandom.hex }".parameterize if self.permalink == nil
end
end
<%= render 'shared/four_breaks' %>
<div class="container-fluid">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<strong style="font-weight: bold; font-size:20px;">STEP 3 (OF 3): ENTER YOUR PAYMENT INFORMATION</strong>
<%= render 'shared/two_breaks' %>
<div class="lg-4 col-lg-offset-4">
<%= simple_form_for @job,
html5: {
class: 'payola-payment-form',
'data-payola-base-path' => main_app.payola_path,
'data-payola-product' => @job.product_class,
'data-payola-permalink' => @job.permalink
} do |f| %>
<p style="color:red"><span class="payola-payment-error"></span></p>
<div class="row">
<div class="col-lg-12">
<label>Your email address
<input type="email" name="job[stripeEmail]" data-payola="email" value="<%= @job.email %>" />
</label>
</div>
<div class="col-lg-12">
<label>Card number
<input type="text" data-stripe="number" />
</label>
</div>
<div class="col-lg-4">
<label>Exp Month
<input type="text" data-stripe="exp_month"/>
</label>
</div>
<div class="col-lg-4">
<label>Exp Year
<input type="text" data-stripe="exp_year"/>
</label>
</div>
<div class="col-lg-4">
<p><label>CVC Code
<input type="text" data-stripe="cvc"/>
</label></p>
</div>
<div class="col-lg-12">
<%= f.submit 'PAY AND DISPLAY AD NOW', class: 'button radius medium expand success' %>
</div>
</div>
<% end %>
<%= render 'shared/two_breaks' %>
<%= link_to (image_tag('big.png')) %>
<%= render 'shared/four_breaks' %>
</div>
</div>
</div>
</div>
类作业nil).where.not('payloa\u sale\u guid'=>nil).where('created\u at>?',30.天前)
结束
def付费?
(!(self.stripeEmail==nil)和&!(self.payloa\u sale\u guid==nil))
结束
私有的
def提供_名称
如果self.name==nil,则self.name='farlung'
结束
def提供_permalink
self.permalink=“#{self.name}{SecureRandom.hex}”。如果self.permalink==nil,则参数化
结束
结束
我认为:
\app\views\jobs\payment.html.erb
class JobsController < ApplicationController
def index
@jobs = Job.paid_ad
end
def show
@job = Job.find(params[:id])
end
def edit
@job = Job.find(params[:id])
redirect_to @job if @job.paid?
end
def update
@job = Job.find(params[:id])
if !(@job.paid?)
@job.update_attributes(stripeEmail: params[:stripeEmail], payola_sale_guid: params[:payola_sale_guid])
@job.update(job_params) unless @job.paid?
redirect_to show_job_path(@job)
else
render :edit
end
end
def new
@job = Job.new
end
def create
@job = Job.new(job_params)
if @job.save
redirect_to preview_job_path(@job)
else
render :new
end
end
def preview
@job = Job.find(params[:id])
redirect_to @job if @job.paid?
end
def payment
@job = Job.find_by_permalink(params[:permalink])
redirect_to job_path(@job) if @job.paid?
end
private
def job_params
params.require(:job).permit(:title, :category, :location, :description, :to_apply, :email, :company_name, :website)
end
end
class Job < ActiveRecord::Base
include Payola::Sellable
validates :title,
:category,
:location,
:description,
:company_name,
:website,
:email,
:to_apply,
presence: true
validates :title, length: { maximum: 75 }
validates :description, length: { minimum: 300 }
validates :to_apply, length: { maximum: 500 }
validates_formatting_of :email, using: :email
validates_formatting_of :website, using: :url
before_validation :provide_name, :provide_permalink
def self.paid_ad
where.not('stripeEmail' => nil).where.not('payola_sale_guid' => nil).where('created_at > ?', 30.days.ago)
end
def paid?
(!(self.stripeEmail == nil) && !(self.payola_sale_guid == nil))
end
private
def provide_name
self.name = 'FarFlung' if self.name == nil
end
def provide_permalink
self.permalink = "#{ self.name } #{ SecureRandom.hex }".parameterize if self.permalink == nil
end
end
<%= render 'shared/four_breaks' %>
<div class="container-fluid">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<strong style="font-weight: bold; font-size:20px;">STEP 3 (OF 3): ENTER YOUR PAYMENT INFORMATION</strong>
<%= render 'shared/two_breaks' %>
<div class="lg-4 col-lg-offset-4">
<%= simple_form_for @job,
html5: {
class: 'payola-payment-form',
'data-payola-base-path' => main_app.payola_path,
'data-payola-product' => @job.product_class,
'data-payola-permalink' => @job.permalink
} do |f| %>
<p style="color:red"><span class="payola-payment-error"></span></p>
<div class="row">
<div class="col-lg-12">
<label>Your email address
<input type="email" name="job[stripeEmail]" data-payola="email" value="<%= @job.email %>" />
</label>
</div>
<div class="col-lg-12">
<label>Card number
<input type="text" data-stripe="number" />
</label>
</div>
<div class="col-lg-4">
<label>Exp Month
<input type="text" data-stripe="exp_month"/>
</label>
</div>
<div class="col-lg-4">
<label>Exp Year
<input type="text" data-stripe="exp_year"/>
</label>
</div>
<div class="col-lg-4">
<p><label>CVC Code
<input type="text" data-stripe="cvc"/>
</label></p>
</div>
<div class="col-lg-12">
<%= f.submit 'PAY AND DISPLAY AD NOW', class: 'button radius medium expand success' %>
</div>
</div>
<% end %>
<%= render 'shared/two_breaks' %>
<%= link_to (image_tag('big.png')) %>
<%= render 'shared/four_breaks' %>
</div>
</div>
</div>
</div>
步骤3(共3步):输入您的付款信息
主应用程序支付路径,
“数据支付产品”=>@job.product\u类,
“数据支付永久链接”=>@job.permalink
}do | f |%>
你的电子邮件地址
卡号
试验月
实验年
CVC代码
我的感觉导致了问题
我感觉导致此错误的原因是,我在带有输入标记的PaymentsView中使用了direct html
您的电子邮件地址
我使用的解决方案
我将视图中的name属性更改为name=“job[stripeEmail]”,它起了作用,但没有将任何内容保存到我的Jobs数据库中
<label>Your email address
<input type="email" name="job[stripeEmail]" data-payola="email" value="<%= @job.email %>" />
</label>
您的电子邮件地址
我真的不能相信这件事。请帮助我。我需要将stripeEmail保存在我的数据库中,因为它是决定工作是否有报酬的属性之一,在我将其显示在索引页之前。我是否遗漏了什么,或者是我的支付/条带配置错误?问题似乎就在这里
@job.update_属性(stripeEmail:params[:stripeEmail],payloa_sale_guid:params[:payloa_sale_guid])
@作业。更新(作业参数),除非@job.paid?
您的参数
结构是“作业”=>{“stripeEmail”=>“afolabiolaoluwa@gmail.com“}
,因此如果要访问stripeEmail
,必须执行以下操作
@job.update_属性(stripeEmail:params[:job][:stripeEmail],payloa\u sale\u guid:params[:payloa\u sale\u guid])
但是您实际上可以删除@job.update_属性(stripeEmail:params[:stripeEmail]
,您只需将:stripeEmail
和:payloa\u sale\u guid
添加到您的作业参数许可证,然后@job.update(job\u params)
将为您执行相同的操作
所以你可以改变
params.require(:job).permit(:title,:category,:location,:description,:to_apply,:email,:company_name,:website)
到
params.require(:job).permit(:title,:category,:location,:description,:to_apply,:email,:company_name,:website,:stripeEmail,:payloa_sale_guid)
更新
关于您在发布的图片中遇到的错误,这是因为在您的表单中,您没有发送任何由job
包装的数据,因此在您的参数中没有类似于{job:{foo:data}}
的内容,但是在您的控制器中,您调用了job\u params
,这需要job
,因此可以进行简单的修复
@job.update(jo