суббота, 4 июля 2015 г.

filter parameter logging

# config/application.rb  

module Blog 

 class Application < Rails::Application  

    config.filter_parameters << :secrets

  end  

end

Symbol to proc

projects = Project.find(:all)
projects.collect { |x| x.name }  = projects.collect(&:name)  //short and cool

Find through association

class Task
   belongs_to :project
end

class Project
   has_many :tasks
end

ProjectController

  @project = Project.find(params[:id])
  @tasks = @project.tasks.find_all_by_column_name(false)

end

RoR / Caching with instance variable


def current_user
   @current_user ||= User.find(session[:user_id])
end