Skip to content

Instantly share code, notes, and snippets.

View universal's full-sized avatar

Johannes / universa1 universal

View GitHub Profile
class UserPasswordResetsController < ApplicationController
#personal preferences here
def update
user = User.find_by(password_reset_token: params[:id])
if !user.present?
head :not_found
elsif !(user.is_activated && user.is_active)
head :unprocessable_entity
elsif user.update_password params[:password], params[:password_confirmation]
head :ok
class Admin < User
has_one :user, :as => :userable
attr_accessible :user
end
@universal
universal / paul.c
Created December 10, 2013 21:21 — forked from anonymous/paul.c
pow(pow(x, n / 2), 2)
pow(x, n / 2) * pow(x, n / 2)
class Feature < ActiveRecord::Base
has_one :project_item, as: :item, class_name: "ProjectItem"
end
class Milestone < ActiveRecord::Base
has_one :project_item, as: :item, class_name: "ProjectItem"
end
irb(main):001:0> User.create(name: "dudu", email: "[email protected]", password: "1234", password_confirmation: "1234")
(1.0ms) begin transaction
User Exists (0.0ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('[email protected]') LIMIT 1
Binary data inserted for `string` type on column `password_digest`
SQL (4.0ms) INSERT INTO "users" ("created_at", "email", "name", "password_digest", "updated_at") VALUES (?, ?, ?, ?
[["created_at", Mon, 18 Nov 2013 20:50:04 UTC +00:00], ["email", "[email protected]"], ["name", "dudu"], ["password_digest
2a$10$ENowSeWI6nGZbVIHVUBfuuwKEWeZ9I81Ci/Nru2Q6Q0.paUi7kFXu"], ["updated_at", Mon, 18 Nov 2013 20:50:04 UTC +00:00]]
(74.1ms) commit transaction
=> #<User id: 5, name: "dudu", email: "[email protected]", created_at: "2013-11-18 20:50:04", updated_at: "2013-11-18 20:50
password_digest: "$2a$10$ENowSeWI6nGZbVIHVUBfuuwKEWeZ9I81Ci/Nru2Q6Q0....">
@universal
universal / Movi.rb
Last active December 26, 2015 05:29 — forked from bluehallu/Movi.rb
class Movie < ActiveRecord::Base
belongs_to :channel
validate :does_not_overlap, :valid_times
def self.from_xml(xml)
id = xml.attr('id') #parse movie id
channel = Channel.find_by_codename(xml.child.name) #get the channel from db
name = xml.child.xpath('name').text #get name
start_time = parse_time(xml.child.xpath('start_time').text)
end_time = parse_time(xml.child.xpath('end_time').text)
class Manufacturer < ActiveRecord::Base
def self.selectable
result = []
result << self.joins(:cars).joins(cars: :basic_articles).where(published: true, cars:{published: true}, basic_articles: {published: true, requires_extra: false}).map{ |r| r.id }
result << self.joins(:cars).joins(cars: :basic_articles).joins(cars: [basic_articles: :extras]).where(published: true, cars:{published: true}, basic_articles: {published: true, requires_extra: true}).map{ |r| r.id }
return self.where(id: result)
end
end
@universal
universal / member.rb
Last active December 23, 2015 23:49 — forked from anonymous/member.rb
class Member < ActiveRecord::Base
belongs_to :project
belongs_to :users
attr_accessible :project_id, :user_id
end
@universal
universal / member.rb
Last active December 23, 2015 23:39 — forked from anonymous/gist:6711528
formatting and mutliple files...
class Member < ActiveRecord::Base
belongs_to :project
belongs_to :users
attr_accessible :project_id, :user_id
end
<p>
<b>Comment:</b>
<%= comment.body %>
</p>
<p>
<%= link_to 'Destroy Comment', [comment.post, comment],
:confirm => 'Are you sure?',
:method => :delete %>
</p>