Monday, March 15, 2010

Many-to-Many Relationship in Rails

Many-to-Many relationships in Rails come in 2 flavors.

  • has_and_belongs_to_many      -> for bare-bones join table

  • has_many :through                      -> for full join models when there is some data associated with the relationship that you want to keep track of

Facebook Login using facebooker

In application_controller.rb
include FacebookerAuthentication::Controller
ensure_authenticated_to_facebook
before_filter :facebook_login_required

check_box_tag() vs check_box()

check_box is for use with a model object.
check_box_tag is when it is not tied with any model and just need a plain checkbox.

Sunday, March 14, 2010

Facbook Canvas : Checkbox

fb:editor-custom
input type="checkbox" style="width:auto;" name="checker" unchecked />March 20
input type="checkbox" style="width:auto;" name="checker" unchecked />March 21
input type="checkbox" style="width:auto;" name="checker" unchecked />March 27
input type="checkbox" style="width:auto;" name="checker" unchecked />March 28
input type="checkbox" style="width:auto;" name="checker" unchecked />April 3
input type="checkbox" style="width:auto;" name="checker" unchecked />April 4
/fb:editor-custom

Facebook Form : Input text - Select from facebook Friends


<%=fb_friend_selector()%>

---------------------------
Note that in your controller, the only thing you will have to do differnt is fish out the facebook params as they are not part of your model, from the freind selector you can get:

friend_name = params[:friend_selector_name]
friend_id = params[:friend_selector_id]

Rails : IDE

RadRails.
http://www.radrails.org/

Friday, March 12, 2010

Setting facebook user_id

Most of the forms in rails are tied to a resource. Submitting a form results in creating an
object of the resource and a record in the table of the model representing that resource.
Submitting a new form is tied to a new method in the controller associated with that resource.

When working in facebook we need to associate a user_id when a from is submitted. This is how the user_id is set in create method.
def create
current_user.honors.create(params[:honor]) - where honor is the resource
redirect_to honors_path
end

Facebook app : IFrame vs. FBML

Thursday, March 11, 2010

Rails Ajax : form_remote_tag vs. remote_form_for

remote_form_for is used when a form is attached to a resource.
------------------------------------
remote_form_for(@post) do |f|
end

form_remote_tag is used when no need to attach a form to a resource.
----------------------------------
form_remote_tag :url => '/posts' do
= submit_tag 'Save'
end

Ajax+ Rails +Facebook app

in application layout file add
<%= javascript_include_tag :defaults %>

"Share" button on WordPress

1.Log-in to your WordPress blog.
2.Click on Plugins in the sidebar.
3.Scroll down to the bottom of the page and click on Plugin Browser/Installer.
4.In the search box, type AddThis, and click Search.
5.Look for the plugin that says AddThis and click on it.
6.In the pop-up window, click Install Now.
7.On the Install page, click the Activate Plugin link
8.(Optional) In Settings > AddThis, add your AddThis.com username, and customize freely

Share WordPress Blog post on Facebook




You can use the plugin 'Share-on-facebook' .
http://wordpress.org/extend/plugins/share-on-facebook/
PHP 5.x is required.
Requires WordPress Version: 2.0 or higher
Compatible up to: 2.9.2

1. Install from your wordpress admin
2. Activate the plugin through the 'Plugins' page in WordPress.
3. Go to 'Settings->Share on Facebook' in your admin interface to select your options.

Facebook app Application Settings

Canvas Callback URL
http://www.domain.com/
Connect URL
http://www.domain.com
Base Domain
www.domain.com
Canvas URL
http://apps.facebook.com/YourFacebookAppName/
FBML/iframe
FBML
Application Type
Website
Post-Authorize URL
http://apps.facebook.com/YourFacebookAppName/

Wednesday, March 10, 2010

DropDown Menu: Rails from Database

<%= f.select("loveaspect_id",
             Loveaspect.find(:all).collect {|c| [c.loveaspect, c.id]},
             {:prompt => "Select a Love Aspet"})%>

Create Form : Facebook app + Rails

The main form of taking input from user is a form. Here is how to create a from Facebook using Rails.

==============================================================

new.fbml.erb

================================================================

<% facebook_form_for @honor do |f| %>

<%= f.text_area :description %>
<%= f.datetime_select :when %>

   
<%= f.select("loveaspect_id",
             Loveaspect.find(:all).collect {|c| [c.loveaspect, c.id]},
             {:prompt => "Select a Love Aspet"})%>
 
 <%= f.buttons "Add" %>
<% end %>

Saturday, March 6, 2010

Invite Friends : Facebook App with Rails

<fb:fbml>
<fb:add-section-button section="profile" />
<% fb_multi_friend_request("Ripple Effect",
"Invite your friends to use Ripple Effect",
invitations_path) do %>
     Ripple Effect your friends. Install Ripple Effect now.
     <%= fb_req_choice("Ripple Effect!",
     new_invitation_url(:from=>@from_user_id, :canvas=>true))%>
     <% end %>
</fb:fbml>

Tabs in Facebook App Canvas with Rails

Code to setup  a tab list of "Tab 1", "Tab 2"

<% fb_tabs do %>
<%= fb_tab_item "Tab 1", "tab1" %>
<%= fb_tab_item "Tab 2", "tab2" %>
<% end %>