Skip to content

Instantly share code, notes, and snippets.

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
private
def current_cart
@current_cart ||= begin
Cart.find(session[:cart_id])
@tbuehlmann
tbuehlmann / helper.rb
Last active August 29, 2015 14:07 — forked from wethu/helper.rb
def form_for_login(&block)
form_for(resource,
as: resource_name,
url: session_path(resource_name),
html: {
class: 'navbar-form navbar-right',
role: 'login'
}, &block)
end
end
class Challenge < AR::Base
belongs_to :category
has_many :participations
has_many :participants, through: :participations
end
<div class="chatboxinput">
<%= form_for([@conversation, @message], :url => conversation_messages_path(@conversation, @message, format: 'js'), :remote => true, :html => {id: "conversation_form_#{@conversation.id}"}) do |f| %>
<%= f.text_area :body, class: "chatboxtextarea", "data-cid" => @conversation.id %>
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<% end %>
</div>
class NotePolicy < ApplicationPolicy
# For index action
class Scope
attr_reader :user, :scope
def initialize(user, scope)
@user = user
@scope = scope
end
class CreateCategories < ActiveRecord::Migration
def change
create_table :categories do |t|
t.string :name
t.timestamps
end
end
end
class CreateGroupLocations < ActiveRecord::Migration
def change
create_table :group_locations do |t|
t.belongs_to :address, index: true, foreign_key: true
t.belongs_to :group, index: true, foreign_key: true
t.timestamps null: false
end
end
end
@tbuehlmann
tbuehlmann / url_stuff.rb
Last active September 12, 2015 07:58 — forked from anonymous/untitled
catch open uri
urls.each do |url|
begin
open(url)
# do some nokogiri things
rescue OpenURI::HTTPError
# log the error
end
end
if params[:friend_id]
friend = User.find(params[:friend_id])
else
# ...
end
Rails.application.routes.draw do
resources :categories
devise_for :admins
devise_for :users
resources :users
namespace :admin do
resources :categories
end