Skip to content

Instantly share code, notes, and snippets.

View tbuehlmann's full-sized avatar

Tobias Bühlmann tbuehlmann

View GitHub Profile
@tbuehlmann
tbuehlmann / a.rb
Created February 10, 2019 11:51
demo
# a.rb
require_relative 'a/b'
module A
end
def rhost(www = nil)
if request.host != "www#{env_dev}.a.a"
request.host.gsub(/^w+(|\d+)\./, "").gsub(/\.a\.a/, "")
elsif www == 1 && request.host == "www#{env_dev}.a.a"
'www'
elsif www == 2
'test'
else
nil
end
require 'rails_helper'
require 'pry'
RSpec.describe UsersController, type: :controller do
let(:climber) { User.create!(email: 'climber@sendroute.com', password: '123456', first_name: 'test', last_name: 'test',
user_name: 'climber') }
let(:setter) { User.create!(email: 'setter@sendroute.com', password: '123456', first_name: 'test', last_name: 'test',
user_name: 'setter', route_setter: true) }
let(:owner) { User.create!(email: 'owner@sendroute.com', password: '123456', first_name: 'test', last_name: 'test',
user_name: 'owner', gym_owner: true) }
%li
= link_to "Remove from collection", remove_from_collection_posts_path(cid: params[:id], pid: post.id), data: { confirm: "Are you sure you want to remove this post?" }, remote: true
@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])
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
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
@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")
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@example.com", "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)
class ApplicationController < ActionController::Base
...
...
include DeviseCustomParams
end