私が構築しようとしている機能により、ユーザーはレストランを訪れることができます。
ユーザー、場所、およびレストランのモデルがあります。場所には多くのレストランがあります。
user_id 属性と restaurant_id 属性を持つ Visits モデルと、create メソッドと destroy メソッドを持つ visits_controller を作成しました。
問題は、実際の Visit レコードを作成できないことです。これを達成する方法について何か考えはありますか?それとも、間違った方法で進んでいますか。
ルーティング エラー
No route matches {:controller=>"restaurants", :location_id=>nil}
コード:
ルート:
location_restaurant_visits POST   /locations/:location_id/restaurants/:restaurant_id/visits(.:format)     visits#create
 location_restaurant_visit DELETE /locations/:location_id/restaurants/:restaurant_id/visits/:id(.:format) visits#destroy
モデル:
class Visit < ActiveRecord::Base
  attr_accessible :restaurant_id, :user_id
  belongs_to :user 
  belongs_to :restaurant
end
意見:
  <% @restaurants.each do |restaurant| %>
    <%= link_to 'Visit', location_restaurant_visits_path(current_user.id, restaurant.id), method: :create %>
    <% @visit = Visit.find_by_user_id_and_restaurant_id(current_user.id, restaurant.id) %>
    <%= @visit != nil ? "true" : "false" %>
  <% end %>
コントローラ:
class VisitsController < ApplicationController
  before_filter :find_restaurant
  before_filter :find_user
  def create
    @visit = Visit.create(params[:user_id => @user.id, :restaurant_id => @restaurant.id])
    respond_to do |format|
      if @visit.save
        format.html { redirect_to location_restaurants_path(@location), notice: 'Visit created.' }
        format.json { render json: @visit, status: :created, location: @visit }
      else
        format.html { render action: "new" }
        format.json { render json: @visit.errors, status: :unprocessable_entity }
      end
    end
  end
  def destroy
    @visit = Visit.find(params[:user_id => @user.id, :restaurant_id => @restaurant.id])
    @restaurant.destroy
    respond_to do |format|
      format.html { redirect_to location_restaurants_path(@restaurant.location_id), notice: 'Unvisited.' }
      format.json { head :no_content }
    end
  end
  private
  def find_restaurant
    @restaurant = Restaurant.find(params[:restaurant_id])
  end
  def find_user
    @user = current_user
  end
end