Active Admin: Form with datepicker on custom page
activeadmin, forms, ruby-on-rails
Solution
add an url to your semantic form, like...
<%= semantic_form_for :newest_rooms, :url => hotel_newest_room_path, :builder => ActiveAdmin::FormBuilder do |f| %>
Problem
Alright I made a custom page in Active Admin called "Newest Rooms" and it shows a table with the Hotel Rooms of the current date. Now I want to add a form the this custom page where I can pick the Date. I've managed to make the form appear with the Datepicker through: ``` <%= semantic_form_for :newest_rooms, :builder => ActiveAdmin::FormBuilder do |f| f.inputs do f.input :Datum, :as => :datepicker end f.buttons end %> ``` But no idea how to send this to the right controller and to the method HotelRoom.newest_rooms I hope someone can explain to me how to do this. I've added the code below: newest_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 %>€</b></td> <td><%= r.OldPrice %>€</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 ```