im noob to rails. 如何从日期选择器获取值以将其传递给另一个方法,以便我可以运行查询。
这是我的控制器:
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
]
}
}
救命!谢谢.. :)
我会使用会话在几个步骤之间进行存储。另请查看表单向导插件/gem,它们也可以为您完成这项工作。
https://github.com/adkron/actsaswizard
查看此截屏视频,它可以帮助您:http://railscasts.com/episodes/217-multistep-forms