I have a user_id column. Instead of calling for all members how can I call up members based on current user's and user_id?
This is my controller, I tried changing .all to user_id or current_user.id plus many variations based on examples. Still can't get it. I also have no models (using authrocket). The create action also works and inserts the user_id, I have a def current_user at the bottom.
class Members::MainsController < ApplicationController
# Security & Action Filters
before_action :set_members_main, only: [:show, :edit, :update, :destroy]
# Member Profile List
@members_mains.user_id = current_user.id
@members_mains = Members::Main.all
# Detailed Member Profile
# New Member Profile
@members_main = Members::Main.new
# Edit Member Profile
# Create Member Profile Action
@members_main = Members::Main.new(members_main_params)
@members_main.user_id = current_user.id
redirect_to members_mains_path, notice: 'Member profile has been successfully created.'
# Update Member Profile Action
redirect_to members_mains_path, notice: 'Member profile has been successfully updated.'
# Delete Member Profile Action
redirect_to members_mains_path, notice: 'Member profile and all businesses was successfully destroyed.'
# Grab User Session Key (For ID)
@_current_user ||= AuthRocket::Session.from_token(session[:ar_token]).try(:user)
# Common Callbacks
@members_main = Members::Main.find(params[:id])
# White List
params.require(:members_main).permit(:mfirstname, :mlastname, :mtitle, :memail, :mphone, :mnotes, :smfacebook, :smtwitter, :smlinkedin, :user_id)
If I got it right, your index action should be something like this:
# Member Profile List def index @current_member = Members::Main.find(current_user.id) end