我目前正在开发一个预订空间在线申请项目。用户可以进行查询,空间的所有者可以接受/拒绝甚至在消息线程中提出反要约。
我们的应用程序似乎更新了术语(self.hire_to.to_date - self.hire_from.to_date).to_i
:
class EnquiryOffer < ActiveRecord::Base
belongs_to :enquiry
has_one :enquiry_state
validates_presence_of :hire_from, :allow_blank => false
validates_presence_of :hire_to, :allow_blank => false
before_save do
EnquiryOffer.where(enquiry_id: self.enquiry_id).update_all(:state => 'inactive')
end
def term
Rails.logger.info "#### Active offer term #{(self.hire_to.to_date - self.hire_from.to_date).to_i}"
(self.hire_to.to_date - self.hire_from.to_date).to_i
end
end
什么似乎是一个问题,当提出还价时,价格不会更新。我猜测如果我在此模型中包含价格,它应该在新的柜台报价时更新。
我是对的吗? (可能不是!)
更新:
查询模型包含这些代码片段,可以让您更好地了解:
def offer_price
puts "price #{self.property.price}"
puts "term #{self.active_offer.term}"
self.property.price * self.active_offer.term
end
def make_offer(conversation_id, offer_id)
states.create! state: "offer_made", conversation_id: conversation_id, enquiry_offer_id: offer_id, receiver_id: self.user_id if open? || offer_rejected? || enquiry_rejected?
end
def active_offer
Rails.logger.info "ACTIVE OFFER #{self.enquiry_offers.where("state = 'active'").first.inspect}"
self.enquiry_offers.where("state = 'active'").first
end
html += action_view.render(:partial => 'messages/message_default', :locals => {:@message => "<h2><i class='glyphicon glyphicon-transfer'></i> You suggested a counter offer</h2> From <b>#{s.enquiry_offer.hire_from.strftime("%d/%m/%y")}</b> to <b>#{s.enquiry_offer.hire_to.strftime("%d/%m/%y")}</b> for <b>£#{self.price.round}</b> with a fee of <b>£#{self.commission(current_user)}</b>.", :@state => s, :@conversation => conversation, :@enquiry => self, :@url => Rails.application.routes.url_helpers.accept_offer_enquiries_path})
elsif s.state == Enquiry::STATES[4]
action_view = ActionView::Base.new(Rails.configuration.paths["app/views"])
action_view.class_eval do
include Rails.application.routes.url_helpers
include ApplicationHelper
def protect_against_forgery?
false
end
end
关键问题是,在提出反要约时,价格与开启询价的初始报价保持一致。