Skip to content

Instantly share code, notes, and snippets.

@Znow
Znow / gist:1010747
Created June 6, 2011 18:13
sessions_helper
module SessionsHelper
#def current_user
#@current_user ||= user_from_remember_token
#end
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
attr_accessor :password # creates a virtual password attribute, only to use in memory
before_save :encrypt_password
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i # full regex
validates :name, :length => { :maximum => 50 },
:presence => true # a validation of :name has to be present and a max character length of 50
class SessionsController < ApplicationController
def new
@title = 'Sign In'
end
def create
# Use the authenticate method from the User model along with the parametres of :session to validate the user login
#user = User.authenticate(params[:session][:email], params[:session][:password])
user = User.authenticate(params[:email], params[:password])
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)
Employee.create([
{
Installing daemons (1.1.3)
Installing eventmachine (0.12.10) with native extensions C:/Ruby192/lib/ruby/sit
e_ruby/1.9.1/rubygems/installer.rb:551:in `rescue in block in build_extensions':
ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildErr
or)
C:/Ruby192/bin/ruby.exe extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... no
def create
@news = News.new(params[:news])
respond_to do |format|
if @news.save
format.html { redirect_to @news, notice: 'News was successfully created.' }
format.json { render json: @news, status: :created, location: @news }
else
format.html { render action: "new" }
format.json { render json: @news.errors, status: :unprocessable_entity }
$ git push -f heroku master
Counting objects: 210, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (170/170), done.
Writing objects: 100% (176/176), 125.46 KiB, done.
Total 176 (delta 99), reused 0 (delta 0)
-----> Heroku receiving push
-----> Rails app detected
-----> Detected Rails is not set to serve static_assets
$ git push -f heroku
Counting objects: 237, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (196/196), done.
Writing objects: 100% (202/202), 128.41 KiB, done.
Total 202 (delta 122), reused 0 (delta 0)
-----> Heroku receiving push
-----> Rails app detected
-----> Detected Rails is not set to serve static_assets
starting
←[36m2011-06-22T22:30:55+00:00 heroku[web.1]:←[0m Starting process with command:
`thin -p 31765 -e production -R /home/heroku_rack/heroku.ru start`
←[36m2011-06-22T22:30:56+00:00 app[web.1]:←[0m /app/.bundle/gems/ruby/1.9.1/gems
/execjs-1.2.0/lib/execjs/runtimes.rb:46:in `autodetect': Could not find a JavaSc
ript runtime. See https://github.com/sstephenson/execjs for a list of available
runtimes. (ExecJS::RuntimeUnavailable)
#gallery model
has_many :images
#image model
belongs_to :gallery
#galleries controller
def show
@gallery = Gallery.find(params[:id])