红宝石在线报价应用程序

时间:2009-11-25 20:08:53

标签: ruby-on-rails ruby

我正在尝试为屋顶构建一个在线报价应用程序。我有一个名为Cost的控制器,它有squarecost和squaresell。还有其他模型和控制器,用于山墙,木瓦,山脊和更多类似的领域。这些附加模型和控制器是报价的附加组件。

理想情况下,销售人员会创建新报价。输入客户信息,它将要求长度“L”,宽度“W”和间距“P”。将有添加的复选框。当销售点击“继续”时,它们将被带到新页面(addon.html.erb),其中包含传递的L,W和P以及之前在页面中检查的所有添加项(在渲染部分中)。

引用包含L,W和P,以及客户名称,电子邮件等其他内容。在引号内我有一个名为getsquare的函数,它从(LxW)xP获取区域,其中P == 1.03(此数字取决于屋顶有多少间距。)Quote存储L,W和P的原因是因为如果检查像Roof Vent这样的材料,那么它会从屋顶获得L来计算需要多少材料。

如何让表单将第一页上的L,W和P传递到第二页,它现在显示所选的所有附加内容?

另外,我在做数学函数时遇到了问题。我对我想做的事情抱有远见,但似乎无法完成它。例如,(@ length * @width)* @pitch =“currentsquare”。 Currentsquare是持有者,因为如果检查Gable然后我需要将Gable方格添加到总数(Gable也有“(L * W)* P = gablesquare”,并且在表格的末尾我有一个“currentsquare + gablesquare = totalsquares“和totalsquares是Quotes中的一个字段。我在哪里可以找到数学函数的wiki和帮助器?我找到的就是Math.floor,Math.log等帮助器。

我知道很多可以用Java完成,但是,试图避免使用Java,这样它也可以用于手机。

2 个答案:

答案 0 :(得分:0)

表单字段在params哈希中传递,可以从控制器访问

<强>更新 搜索表单

  def search
    @find = params[:find] ? true : false
    @user_filter = params[:user_filter] ? params[:user_filter].strip : ''
    @dj_filter = params[:dj_filter] ? params[:dj_filter].strip : ''
    @date_from = params[:date_from] ? Date.civil(params[:date_from][:year].to_i, params[:date_from][:month].to_i, params[:date_from][:day].to_i) : Time.now - 1.year
    @date_to = params[:date_to] ? Date.civil(params[:date_to][:year].to_i, params[:date_to][:month].to_i, params[:date_to][:day].to_i) : Time.now + 1.day
    @requests = []
    if @find
      users = User.find :all, :conditions => ["login LIKE ?", "%" + @user_filter.downcase + "%"]
      djs = User.find :all, :conditions => ["login LIKE ?", "%" + @dj_filter.downcase + "%"]
      conditions = (@user_filter.empty? ? "" : "(user_id in (#{users.map {|u| u.id}.join(",")})) and ") +
              (@dj_filter.empty? ? "" : "(dj_id in (#{djs.map {|u| u.id}.join(",")})) and ")
      @requests = Request.find :all,
                :conditions => [conditions + "(created_at between ? and ?)", @date_from, @date_to],
                :order => "created_at DESC",
                :limit => 100
    end
    respond_to do |format|
      format.html
      format.xml
    end
  end

相关部分是:

params[:user_filter], params[:dj_filter], params[:date_from], etc.. 

答案 1 :(得分:0)

  

我有一个名为Cost的控制器,它有squarecost和squaresell。还有其他模型和控制器用于山墙,木瓦,山脊等更多类似领域。

我不熟悉屋顶词汇,所以我会做一些假设。

假设1:你的意思是你有一个成本“模型”而不是控制器。控制器通常具有“新”,“创建”,“更新”,“显示”或“删除”等操作。

假设2:您有“几种与屋顶相关的工作”,并且您希望根据宽度,高度,间距和类型发出成本。我还假设计算结果根据类型的不同而不同。

如果你想在你的数据库上保存你的W,L和P,你可以使用single table inheritance - 你可能会有类似的东西,而不是让所有“类型的屋顶”模型继承自ActiveRecord :: Base这样:

#app/models/roof.rb
class Roof < ActiveRecord::Base
  validates_presence_of width, height, pitch
  validates_numericallity_of width, height, pitch
  ... (general calculations with width, height, pitch - maybe squarecost & squaresell )
end

然后你的Gable模型会是这样的:

#app/models/gable.rb
class Gable < Roof #instead of ActiveRecord::Base
  ... (gable-related validations and calculations)

您的屋顶桌至少需要用于宽度,高度,间距和类型的柱子(“屋顶类型”)。加上所有类型的所有附加字段 - 例如,如果Gable有一个名为“material_id”的字段,您也必须将它包含在Roof表中。

我认为你需要那个解决方案。但是,如果您不想在数据库中存储宽度,高度和间距,则必须在lib /目录中创建一个模块,并自己实现验证。像这样:

#lib/roof.rb
module Roof
  attr_accessor :width, :height, :pitch
  def validate_dimensions
    ... (add errors to the model if with, height or pitch are missing or non-numeric)
  end
  ... (again, general calculations here)
end

然后在您的山墙模型上:

#app/models/gable.rb
require roof.rb #you could also include this on an initializer
class Gable < ActiveRecord::Base
  include Roof
  ... (Gable-specific validations)
  validate :validate_dimensions #this must be put after all other validations
  ... (Gable-specific stuff)
end

在这两种情况下,Gable控制器&amp;观点会是一样的:

#app/controllers/gable_controller.rb
class GableController < ApplicationController
  def new
    @gable = Gable.new()
    ... (usual scaffolding-generated stuff for new, create, show, etc.)
end

#app/views/gable/new.html.erb
... (header, title, etc)
<% form_for @gable do |f| %>
  <%= f.text_field :width %>
  <%= f.text_field :height %>
  <%= f.text_field :pitch %>
  ... (gable-specific fields)
<% end %>

如果缺少高度和音高,此表格将抛出常见错误。

我希望这可以帮助你 - 我实际上并没有运行代码,因此可能存在拼写错误。