Skip to content

Instantly share code, notes, and snippets.

resource :report do
resources :subjects, only: :index
end
@tbuehlmann
tbuehlmann / login_check.rb
Last active March 6, 2016 12:46
login error message/alert
def authenticate
if params[:username].present? && params[:password].present?
inn = Inn.find_by(username: params[:username])
if inn
authenticated = inn.authenticate(params[:password])
if authenticated
redirect_to inns_url, notice: 'You are now logged in.'
return
# app/drops/invoice_drop.rb
class InvoiceDrop < Liquid::Drop
delegate :days_late, :priceinbtw, :print_date, :id, :late, :unpayed, to: :invoice
attr_reader :invoice
def initialize(invoice)
@invoice = invoice
end
class State < ActiveRecord::Base
def self.default
find_by(default: true)
end
def make_default!
PgLock.new(name: 'set_state_default').lock do
State.update_all(default: false)
update(default: true)
end
class ApplicationController < ActionController::Base
...
...
include DeviseCustomParams
end
Started PATCH "/users/28/edit" for 192.168.0.100 at 2016-09-23 22:40:26 +0200
Processing by UsersController#edit as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"BILLq+y8oXYL6aECCZCPONCAalsaKMYfZWFB50J3kNRQCSdt1Fy+X17fExIXML0bi5p00mH07lXXJNKOecytjA==", "user"=>{"name"=>"Name Update", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "button"=>"", "id"=>"28"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 28], ["LIMIT", 1]]
Rendering users/edit.html.erb within layouts/application
Rendered shared/_errors.html.erb (0.4ms)
Rendered users/edit.html.erb within layouts/application (3.6ms)
Rendered application/_favicon.html.erb (8.4ms)
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 28], ["LIMIT", 1]]
Rendered layouts/_header.html.erb (3.6ms)
@tbuehlmann
tbuehlmann / model.rb
Created October 13, 2016 12:11 — forked from bsylvain/model.rb
can it be reduced to a one liner ?
validate :relation_with_same_tenant
.......
private
def relation_with_same_tenant
if self.shop_id!=ui_listable.shop_id
self.errors.add(:ui_listable,"ERROR MESSAGE")
class CreateReleaseSteps < ActiveRecord::Migration[5.0]
def change
create_table :release_steps do |t|
t.belongs_to :release, index: true
t.string :name
t.string :loadbalancer
t.string :comment
t.integer :release_id
end
end
class AddPriceToLineItem < ActiveRecord::Migration[5.0]
def change
add_column :line_items, :price, :decimal
LineItem.includes(:product).find_each do |li|
li.update(price: li.product.price)
end
end
end
@tbuehlmann
tbuehlmann / searh.rb
Last active March 3, 2017 21:04 — forked from foliwe/searh.rb
search
class BooksController < ApplicationController
def index
@books = Book.all
end
def search
@books = Book.all
if params[:price].present?
@books = @books.where('price <= ?', params[:price])