我有问题我将对象ID传递给一个控制器到另一个控制器之间我使用devise gem执行sign_in操作,当sign_in完成后下一页显示错误“活动记录::RecordNotFound BookingController#index”和“找不到没有空间an id" ## 我在步骤 1 中执行操作:当我浏览到 "guest_search" 页面时,我使用 "Ransack gem" 执行搜索操作,当搜索完成时,我使用 params[:id] 获取特定 id 并发送到另一个控制器文件房间控制器.rb
2:发送另一个控制器时执行“before_filter :authenticate_user!” 在新控制器上,如果用户 sing_in 并呈现新控制器操作会给出错误“活动记录::RecordNotFound BookingController#index”和“找不到没有 id 的房间”
房间控制器.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 %>