Skip to content

Instantly share code, notes, and snippets.

View raysrashmi's full-sized avatar
🏠
Working from home

Rashmi Yadav raysrashmi

🏠
Working from home
View GitHub Profile
@raysrashmi
raysrashmi / in console
Created June 14, 2012 17:10
authentication error while using Twitter.user_search('rays')
```ruby
1.9.3p194 :006 > Twitter.configure do |config|
1.9.3p194 :007 > config.consumer_key = PROVIDER['twitter']['key']
1.9.3p194 :008?> config.consumer_secret = PROVIDER['twitter']['secret']
1.9.3p194 :009?> config.oauth_token = PROVIDER['twitter']['oauth_token']
1.9.3p194 :010?> config.oauth_token_secret = PROVIDER['twitter']['oauth_token_secret']
1.9.3p194 :011?> end
=> Twitter
1.9.3p194 :012 > Twitter.user_search('rays')
@raysrashmi
raysrashmi / configinitializerwarden.rb
Created June 21, 2012 08:53
Basic Http auth with warden
Rails.configuration.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Not for public eyes") do |u, p|
u == 'foo' && p == 'bar'
end
params[:user] = {:name => 'Foo',:email => '[email protected]'}
@user = User.new(params[:user])
@user = User.update_attributes(params[:user])
class Account < ActiveRecord::Base
has_many :rooms
accepts_nested_attributes_for :rooms
end
class Room < ActiveRecord::Base
belongs_to :account
end
class User < ActiveRecord::Base
attr_protected :admin
end
class User < ActiveRecord::Base
attr_accessible :name
end
class BooksController < ApplicationController
def create
@book = Book.new(params[:book], as : user_role)
respond_to do |format|
if @book.save
format.html { redirect_to @book notice 'Book was successfully created.' }
else
format.html { render action : "new" }
end
end
class Book < ActiveRecord::Base
attr_accessible :name, :public, :author
end
class Book < ActiveRecord::Base
attr_accessible :name, :author, :public as : :admin
attr_accessible :name, :author, as : :user
end