我怎样才能从datepicker传递并获取值?

时间:2011-05-12 01:55:55

标签: ruby-on-rails sql-server-2005 ruby-on-rails-3

im noob to rails。我如何从我的datepicker获取值将其传递给另一个方法,以便我可以运行我的查询。

这是我的控制器:

def index
    redirect_to(:action => 'step1') 
end

def step1
    @checkin = params[:checkin]
    @checkout = params[:checkout]
end

def step2
    checkin = @checkin
    checkout = @checkout
    @amenities = Amenity.available(checkin, checkout)
end

我的观点

    <%= label_tag @checkin, "From:" %>
    <%= text_field_tag "checkin", @checkin %>
    <%= label_tag @checkout, "To:" %>
    <%= text_field_tag "checkout", @checkout %>

    <%= button_to "Show Availability", :action => "step2" %>

以及我运行查询的模型:

scope :available, lambda {
    |checkin, checkout| { 
      :select => 'amenities.*',
      :order => 'id',
      :conditions => ["
        amenities.id NOT IN 
        (
          SELECT aa.id from amenities aa, amenity_list al WHERE
          amenities.id = al.amenities_id AND
          (
            (? BETWEEN al.checkin AND al.checkout) OR
            (? BETWEEN al.checkin AND al.checkout)
          )
        )", 
        checkin, 
        checkout
      ] 
    }
  }

HELP!谢谢.. :))

1 个答案:

答案 0 :(得分:0)

我会使用会话来存储几个步骤。 另请查看表单向导插件/宝石,这也可以为您完成工作。

https://github.com/adkron/actsaswizard

CheckOut也是这个Screencast,它可以帮助您: http://railscasts.com/episodes/217-multistep-forms