Railsを初めて使用し、次のことを実行しようとしていますが、安全に実行していないと感じています。
私のサイトへの訪問者は、ユーザーのプロフィールページを表示し、登録せずにユーザーに連絡できます。ユーザーと訪問者の間にはhas_and_belongs_to_manyの関係があります。訪問者がユーザーに連絡したときに、訪問者テーブルに送信された情報を使用して新しいレコードを作成し、users_visitorsテーブルに新しい関係を作成して、後でユーザーに送信された情報を表示できるようにします。私がこれまでに持っているもの:
モデル:
class User < ActiveRecord::Base
has_and_belongs_to_many :visitors
class Visitor < ActiveRecord::Base
has_and_belongs_to_many :users
ビュー:user / profile.html.erb
#this is at example.com/user/id
<%= form_for Visitor.new, :url => contact_path, :html => { :method => :post } do |f| %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= submit_tag("Submit") %>
<% end %>
ルート.rb
#this will just point to a confirmation page
post '/contact', to: 'visitors#contact', :as => :contact
私は2つの部分で迷子になっています:関係を作成するために必要なユーザーIDを渡す/使用するにはどうすればよいですか?また、この新しい関係を作成するためにコントローラー(またはモデル)はどのように見えるべきですか?