2:当发送另一个控制器执行" before_filter:authenticate_user!"在新控制器上如果用户sing_in并呈现新的控制器动作则给出错误"活动记录:: RecordNotFound BookingController #index"和#34;找不到没有身份证的房间"
RoomController.rb
class RoomsController < ApplicationController
def guest_search
@search = Room.search(params[:q])
@roome = @search.result(:distinct => true)
@room= @roome.where("status IS ?", true).order("room_type_id desc")
end
end
guest_search.html.erb
<%= search_form_for @search, url: guest_search_rooms_path, html: {:method =>:post} do |f| %>
<%= f.label :start_date_eq , "Start Date"%>
<%= f.text_field :start_date_eq, class: 'release_date' %>
<%=f.label :end_date_lteq, "End Date" %>
<%= f.text_field :end_date_lteq, class: 'release_date' %>
<%= f.label :Location %>
<%= f.collection_select :location_id_eq, Location.all, :id, :locationname, :include_blank => true %>
<%= f.label :RoomType %>
<%= f.collection_select :room_type_id_eq, RoomType.all,:id,:room_type, :include_blank => true %>
<%= f.submit "search" %>
<% end %>
<table class="table table-bordered" border=1 align="center">
<tr>
<th style="width: 5%">No.</th>
<th style="width: 20%">room_no</th>
<th style="width: 20%">status</th>
<th style="width: 10%">room_type</th>
<th style="width: 20%">StartDate</th>
<th style="width: 10%">EndDate</th>
<th></th>
</tr>
<% $i=0 %>
<% @room.each do |room| %>
<tr class="<%= cycle('odd','even') %>">
<td><%= room.room_no %></td>
<td><%= room.status %></td>
<td><%= room.room_type.room_type %></td>
<td><%= room.start_date %></td>
<td><%= room.end_date %></td>
<td><%= link_to("Book Now", bookings_path(@room) ,:class=> "btn btn-info") %></td>
</tr>
<% end %>
</table>
BookingController.rb
class BookingsController < ApplicationController
def index
@room = Room.find(params[:id])
end
end
index.html.erb
<h2>Welcome to booking</h2>
<%= @room.id %>