title: Trouble with current_user in Join Table
body: <p>I'm working on a join table called Languages_User, that has and belongs to many Languages and Users. Users was created with the devise gem. I want a form to be filled out, and the user_id to automatically be populated into the Languages_User table. I feel like I have tried everything, and this seems like a simple task, but hopefully someone can give me some insight into what is wrong:</p>
  
  <pre><code>class LanguagesUsersController &lt; ApplicationController
  
    def new
      @languages_user = LanguagesUser.new
      #@user_id = current_user    
    end
  
    def create
      if user_signed_in?
        #@user = current_user
        @languages_user = LanguagesUser.new(languages_user_params)
        #@languages_user.language_id = params[:languages_user][:language_id].to_i
        #@user_id = user_id.to_i
  
        respond_to do |format|
          if @languages_user.save
             format.html { redirect_to @languages_user, notice: 'Proficiency was successfully created.' }
             format.json { render :show, status: :created, location: @languages_user }
          else
             format.html { render :new }
             format.json { render json: @languages_user.errors, status: :unprocessable_entity }
          end
        end
  
      else
        puts 'You must be logged in'
        redirect_to new_languages_user_path
      end
    end
  
    private
    # Never trust parameters from the scary internet, only allow the white list through.
    def set_languages_user
      @languages_user = LanguagesUser.find(params[:id])
    end
  
    def languages_user_params
      params.require(:languages_user).permit(:language_id, :level, users_attributes: [:id])
    end
  </code></pre>
  
  <p>And the _form.html.erb</p>
  
  <pre><code>&lt;%= form_for(@languages_user, method: :post) do |f| %&gt;
     &lt;% if @languages_user.errors.any? %&gt;
        &lt;div id="error_explanation"&gt;
          &lt;h2&gt;&lt;%= pluralize(@languages_user.errors.count, "error") %&gt;prohibited this language from being saved:&lt;/h2&gt;
          &lt;ul&gt;
            &lt;% @languages_user.errors.full_messages.each do |message| %&gt;
              &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
            &lt;% end %&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
     &lt;% end %&gt;
     &lt;div class="field"&gt;
       &lt;%= f.label :level %&gt;&lt;br&gt;
       &lt;%= f.number_field :level %&gt;
     &lt;/div&gt;
     &lt;div class="field"&gt;
       &lt;%= f.collection_select(:language_id, Language.order('language ASC').all, :id, :language) %&gt;&lt;br&gt;
     &lt;/div&gt;
     &lt;div class="actions"&gt;
       &lt;%= f.submit  %&gt;
     &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>First question here, so forgive me if it's not properly asked :)</p>