我只是试图通过事件的索引页面访问显示页面,但我不断收到这个 mongoid 错误-
Mongoid::Errors::DocumentNotFound at /events/%23%3CMongoid::Criteria:0x007f8ac1da9578%3E
Summary:
When calling Event.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): # ... (1 total) and the following ids were not found: #. Resolution:
Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples.
控制器
def index
@event = Event.all
end
def show
@event = Event.find(params[:id])
end
路线
resources :events do
resources :leads, only: [:new, :create]
resources :registrations, only: [:new, :create]
end
索引视图
<ul>
<% @event.each do |e| %>
<li><%= link_to e.title, event_path(@event) %></li>
<% end %>
</ul>