简体   繁体   中英

Active Admin: add a form to new page

I created a new page with Active Admin. It currently just shows a table which lists all entries of the model "HotelRoom" for the current date.

Now I want to add a form where I can choose the Date for the data displayed in the table. But I can't get my head around how to add the form.

Forms usually look like this:

<% form_for @hotel_rooms do |f| %>
  <p>
    <%= f.label :date %><br />
    <%= f.text_field :date %>
  </p>
  <p><%= f.submit "Submit" %></p>
<% end %>

and then I want to add a datepicker to the textfield like described here http://railscasts.com/episodes/213-calendars But I always get the error:

undefined method `model_name' for NilClass:Class

What am I doing wrong?

EDIT: I tried adding the variable to the controller like this in the custom page file

 controller do
  def index
    @hotel_rooms = HotelRoom.all
  end
 end

but still no luck. Same error.

As usual - you have your @hotel_rooms variable not set in Controller at all ( or item with provided conditions was not found in DB ).

Update:

Otherwise - try to use:

form_for :hotel_room ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM