5

好吧,我在 Active Admin 中创建了一个名为“最新客房”的自定义页面,它显示了一个包含当前日期酒店客房的表格。

现在我想在这个自定义页面中添加一个表单,我可以在其中选择日期。我设法通过以下方式使表单与 Datepicker 一起出现:

<%= semantic_form_for :newest_rooms, :builder => ActiveAdmin::FormBuilder do |f|
   f.inputs do
     f.input :Datum, :as => :datepicker
   end
   f.buttons
end %>

但不知道如何将其发送到正确的控制器和方法 HotelRoom.newest_rooms

我希望有人可以向我解释如何做到这一点。我添加了以下代码:

latest_room.rb

ActiveAdmin.register_page "Newest Rooms" do

  menu :label => "Newest Rooms"


  content do
      render "newest_rooms"
  end
end

_newest_room.html.erb

<% @cities = Hotel.cities %>

<%= semantic_form_for :newest_rooms, :builder => ActiveAdmin::FormBuilder do |f|
   f.inputs do
     f.input :Datum, :as => :datepicker
   end
   f.buttons
end %>

<ul class="room_list">
<% @cities.each do |c| %>
<li>
    <table>
    <tr>
        <td>
            <h2><%= c.City %></h2>
        </td>
    </tr>
    <tr class="room_column">
        <td>Hotel</td>
        <td>Free Rooms</td>
        <td>BN-Price</td>
        <td>Old Price</td>
    </tr>
    <% @rooms = HotelRoom.newest_rooms(c.City) %>
    <% @rooms.each do |r| %>
    <tr>
        <td><%= r.hotel.Hotelname %></td>
        <td><%= r.FreeRooms %></td>
        <td><b><%= r.Price %>€&lt;/b></td>
        <td><%= r.OldPrice %>€&lt;/td>
    </tr>   
    <%end%>

</table>
</li>
<% end %>
</ul>

hotel_room.rb

class HotelRoom < ActiveRecord::Base
  validates :title, :presence => true
  self.table_name = "hotel_room"

  belongs_to :hotel, :foreign_key => 'H_ID'
  accepts_nested_attributes_for :hotel 


  def to_key
    [self.ID]
  end


  def self.newest_rooms(city)

      HotelRoom.find(:all, :joins => :hotel, :conditions => ["hotel.City = ? and hotel_room.Date = ?", city, Date.today])

  end

end
4

1 回答 1

3

将 url 添加到您的语义形式中,例如...

<%= semantic_form_for :newest_rooms, :url => hotel_newest_room_path, :builder => ActiveAdmin::FormBuilder do |f| %>
于 2012-06-04T19:22:20.023 回答