小编thi*_*non的帖子

验证除Rails中的一个属性之外的所有属性

我正在尝试使用valid?方法在我的模型中进行自定义验证.我需要运行此模型的所有验证,但密码除外.

像这样的东西:

@resource = SalesPartner.new(permitted_params.merge(parent: current_sales_partner))

respond_to do |format|

  if @resource.valid?(except: :password)
    @resource.generate_authentication_token

    SalesPartnerMailer.mail_new_sales_partner(@resource.email,
      { auth_token: @resource.authentication_token, id: @resource.id, level: @resource.level }
    ).deliver

    flash[:success] = "#{@resource.level} criado com sucesso."
    format.html { render "#{@path}/index" }
  else
    logger.log_and_alert_save_error(@resource, flash, "Ocorreu um erro ao salvar.")
    format.html { render "#{@path}/new" }
  end

end
Run Code Online (Sandbox Code Playgroud)

那可能吗?

感谢大家!

validation ruby-on-rails

5
推荐指数
1
解决办法
1254
查看次数

为整个Prawn PDF文档设置动态高度

当我尝试使用Prawn gem for Rails 生成文档时,我遇到了问题

我要做的是为我的pdf设置一个可变高度,因此根据数据库中的一些查询,PDF高度将会改变.我这样做是因为我需要单页PDF文档.

目前,我的代码如下所示:

pdf = Prawn::Document.new(page_size: [297.64, 419.53], margin: 0)

....

data = [ ["Header1", "Header2", "Header3", "Header4", "Header5", "Header6"] ]

// here is the variable data
cart.cart_products.each do |cp|
  arr = [
    cp.product_code,
    cp.product_description,
    cp.amount,
    cp.product_metric,
    cp.product_unit_value,
    cp.total_value
  ]

  data.push(arr)
end

// populating the table with data
pdf.table(data, :cell_style => {:border_width => 0}, :column_widths => [45, 80, 30, 42.36, 50, 50]) do |table|
  table.row(0).border_width = 0.1.mm
  table.row(0).font_style = :bold
  table.row(0).borders = [:bottom]
end

.... …
Run Code Online (Sandbox Code Playgroud)

pdf ruby-on-rails prawn

4
推荐指数
1
解决办法
869
查看次数

标签 统计

ruby-on-rails ×2

pdf ×1

prawn ×1

validation ×1