I know this is stupid, but I want to know how we can create the current_user method to access the entire application without using any gem or plugin? To test it, I created an application that allows the user to share files and folders. How to create a method in which the user can access only his folder and files? Here is my sample code:
Input controller:
class LoginController < ApplicationController layout 'signup' #to skip checking the authentication and authorization. skip_before_filter :check_authentication, :check_authorization def index end def authenticate if request.post? user = User.authenticate(params[:username],params[:password]) if user session[:current_user_id]=user.id session[:name]= user.first_name puts "session name #{session[:name]}" redirect_to(:subdomain => user.company.subdomain, :controller => :dashboard) else flash.now[:notice] = "Invalid user/password combination" end end end def destroy session[:current_user_id] = nil reset_session flash[:notice] = "You have been successfully logged out." redirect_to root_url end end
User Model:
require 'digest/sha1' class User < ActiveRecord::Base
I want to access all files as "current_user.files", is this possible without any gem?
Application Helper:
module ApplicationHelper
Application controller:
class ApplicationController < ActionController::Base include UrlHelper
and in the task controller:
class TasksController < ApplicationController
and my error message I received:
NameError in TasksController#index undefined local variable or method `current_user' for #<TasksController:0xfa7e638>
source share