How to update all in mongoid

March 4, 2012 § Leave a comment

in Active record we simply use Model.update_all() then how we do that in mongoid ?
simple.. use collection.update, example:

Article.collection.update({:user_id => self.id}, {"$set" => {:status => self.status}}, {:multi => true})

Save Facebook user data into the database after Authentication using Oauth2

November 13, 2011 § 2 Comments

This post is a reply from someone who emailed me, he asked me how to save the user data that already login to our site using facebook graph API.
after we create a login scheme using facebook and oauth2 gem, we need to save the facebook user data to our databases, so.. how to save it into the database?

it’s very easy and simple, when we get a callback from the facebook graph API and save the user data in session like this:

session[:fb_user] = JSON.parse access_token.get('/me')
session[:user] = User.save_user_data(session[:fb_user])

« Read the rest of this entry »

how to make layout false for devise controller

July 5, 2011 § Leave a comment

since I wanna use the login page as a popup box use facebox.. not to redirected the user. the whole layout is appear to the facebox.. so how to make the layout false if we use devise?

simple.. check the current controller is a Devise::SessionsController or not in ApplicationController :

class ApplicationController < ActionController::Base
  layout :layout

  private

  def layout
    is_a?(Devise::SessionsController) ? false : "application"
  end

end

How to solve `cached_specs': undefined method `spec’ for nil:NilClass error

October 27, 2010 § 6 Comments

I try to run “bundle install” (bundler gem) and in the middle of the installation process i got my hardisk space is full. so i cut the process and remove some data then try to install again, so i run the “bundle install” again and get error like this :

/usr/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/source.rb:199:in `cached_specs': undefined method `spec' for nil:NilClass (NoMethodError)

from/usr/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/source.rb:196:in `each’

from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/source.rb:196:in `cached_specs’

and many moooorreeee…..

that error caused of « Read the rest of this entry »

Create Recurring job using delayed job

July 29, 2010 § 4 Comments

basically delayed job is using for background job. but we can use it as a recurring job.
here’s the step

first, install delayed_ojb gem. you can see how to install it at
http://github.com/collectiveidea/delayed_job

then add a new library to your rails apps directory ( /Libs ) e.g: jobs.rb « Read the rest of this entry »

facebook authentication using oauth2 gem in rails

July 26, 2010 § 3 Comments

in this section,  i wanna share how to intregrate the Facebook’s new OAuth authorization in Ruby On Rails, using oauth2 gem.

let’s get started !

first, install the oauth2 gem, you can get it from here

http://github.com/intridea/oauth2

then create a controller call oauth_controller.rb « Read the rest of this entry »

Follow

Get every new post delivered to your Inbox.