Wednesday, 8 February 2012

Blocking default design present in application layout


This is the way from where you are calling your default sidebar in application.html.erb


<div id="define_according_to_your_stylesheet" class="<%= sidebar_disabled? %>">
<!-- START Sidebar -->
                 <%= yield :sidebar %>
                 <%= app_screen_tip -%>
<!-- END Sidebar -->
     </div>

Here <%=sidebar_disabled? %> is calling method present in application helper


define a method in application helper which is loaded automatically when your application loaded


def sidebar_disabled?
    current_page = "#{controller.controller_name}.#{controller.action_name}"
    current_controller = controller.controller_name
    pages = %w(
      home.index
#comment [home(its your controller name).index(its your action)]
   
)    return pages.include?(current_controller) || pages.include?(current_page)
  end



by this way you can block anything which loaded by default when application loaded



Monday, 6 February 2012

Download YouTube Videos from Ubuntu 11.10


YouTube Video Downloader in Ubuntu 11.10

You can use various ways to download a youtube video into your ubuntu 11.1o. Using a yoututbe client, a command lineutility, a web browser plugin are available for downloading videos from youtube.

MiniTube

Minitube is the best youtube client in ubuntu 11.1o. You can watch Youtube Videos right from your desktop. You can easly download youtube videos into ubuntu 11.10 using minitube. It has a very simple and easy GUI. You can configure the video size, related videos etc. You can easily search using keywords or a youtube channel name. The project is hosted in gitorius and is released as GPL.

Install Minitube, The Youtube Downloader in Ubuntu 11.10

Minitube is available in official package repository. To install minitube just type the command in command line.
sudo apt-get install minitube
you can install using Ubuntu Software Centre also. Just search for minitube in the software centre and click install.

Download videos using MiniTube in Ubuntu 11.1o

To download a video just play the video in minitube. The go Video > Download in the menu. The videos will be saved to /home/username/Videos.
 Download Youtube Videos Using Terminal Utility
You can download youtube videos by using the command line. To download videos from command line you can use the command youtube-dl.  Install install a utility  youtube-dl. Open terminal and type
sudo apt-get install youtube-dl
Now, open the youtube video in the browser and copy the URL from the address bar.
Then execute the following command -
youtube-dl "http://youtube.com/?v=VideoID"

IE9 DELETES stuff

THANKS TO:- 
            http://techno-weenie.net/2011/8/19/ie9-deletes-stuff   (FROM WHERE I GOT THIS INFORMATION)



Using more of the HTTP methods lets us keep the URLs cleaner. Web browsers don't understand PUT/PATCH/DELETE in forms, so a workaround was needed. Rails looks at a _method GET parameter on POST requests to determine what HTTP verb it should be recognized as. The GData API supports this behavior through the X-HTTP-Method-Override header.
A typical Rails controller might look like this:

class WidgetsController < ApplicationController
  # DELETE /widgets/1
  def destroy
    @widget.destroy
    redirect_to '/widgets'
  end
end

If you don't like Rails, just close your eyes and think of your favorite web framework...
This action works great for a simple form in a browser. You click "Submit", it POSTs to the server, and then you end up back at the root page. Then, you can add some jQuery to spice things up for newer browsers. Progressive enhancement and all that.

$('.remove-widget').click(function() {
  $.del(this.href, function() {
    // celebrate, disable a spinner, etc
  })
  return false
})

This works great in all modern browsers, except IE9. We discovered that not only does IE9 send a real DELETE request, it also follows the redirect with another DELETE. If that redirect points to another resource, you can get a dangerous cascading effect.
RFC 2616 is not clear about what to do in this case, but strongly suggests that redirects are not automatically followed unless coming from a safe method.
If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.
Standard practice for browsers over the years is that redirects from POST requests are followed with a GET request. GET/HEAD requests are usually safe, so this seems like reasonable behavior. It's expected by web developers, and consistent across browsers.

I can't imagine that this behavior in IE9 was on purpose. It feels like an edge case that slipped through an if statement because "DELETE" != "POST". I've submitted feedback to the IE9 team about this issue. I'm curious to see what they say.

So, if your application might be responding to ajax requests with redirects, you should probably start sending back 200 OK...


Update: Eric Law on the IEInternals blog responded to one of Kyle's tweets. Apparently the behavior is correct according to HTTP 1.0, and IE has been following DELETE redirects since at least IE6.
Here's the breakdown of browser behavior when receiving a 302 redirect from a DELETE request:

IE 6-10 DELETE method is preserved
Chrome 13 Converts to GET
Firefox 6 Converts to GET
Safari 5.1 Converts to GET
Opera 11.5 Converts to GET

We didn't see the behavior in IE8, so we assumed it was new to IE9. At least, no one was sending in crazy bug reports from other browsers. This is another example why developers hate dealing with IE. Kudos to the standards compliance, though!



Installing a gem fork from Github source

THANKS TO:-
                    http://raflabs.com/blogs/silence-is-foo/2010/07/19/installing-a-gem-fork-from-github-source/




Usually, installing a gem is as easy as issuing:

1.gem install gem_name

but, what if you want to install a fork of a gem?
As you may know Github no longer hosts gems, so doing the following won't work:

$ sudo gem install technoweenie-grit --source http://gems.github.com

NOTE: Actually it'd work if the gem you're trying to install is in this list: http://gems.github.com/list.html

Disecting the "Download Source" button

Let's suppose we want to install the Techno Weenie's fork of Grit from Github:
Main repo => http://github.com/mojombo/grit
Techno Weenie's fork => http://github.com/technoweenie/grit
Github has a "Download Source" button, if you click it you'll be presented with two big images (say buttons): "ZIP" and "TAR", clicking these buttons will start downloading the code of the master branch in the selected format; below those buttons you'll find the list of tags of the repository, you'll be able to click one of the tags and again you'll be presented with "ZIP" and "TAR" to download the source of such tag.

How does this works?

This is how the URL is built:

http://github.com/USER/REPOSITORY/FORMAT/BRANCH_OR_TAG

"ZIP" => http://github.com/technoweenie/grit/zipball/master
"TAR" => http://github.com/technoweenie/grit/tarball/master
said this:


1.$ wget http://github.com/technoweenie/grit/zipball/master
2. 
3.$ unzip technoweenie-grit-v2.0.0-12-g0bd0c5f.zip
4. 
5.$ cd technoweenie-grit-0bd0c5f


Installing the gem

Gems source code has a special file called gem_name.gemspec, this is like the DNA of the gem and it's used to build it:

1.$ gem build grit.gemspec

Issuing this command will generate a gem_name-version.gem file which is the gem itself, let's install it:

1.$ sudo gem install grit-2.0.0.gem

Some projects doesn't have a .gemspec file but rake tasks, in that case you just need to do:

1.$ rake build
2.$ rake install

If any of these methods work, you'd have to look at the Rakefile for tasks to generate the .gemspec file.
...and we're done!

NOTE: 'gem build' will not take in consideration special and external dependencies the gem might require, so you must take care of the dependencies manually. Check in the code all the 'require' lines to see dependencies.
Hope it helps.



Gems On Rails Get Version 0.7.2 → ‘gemsonrails’


THANKS TO:-
                             http://gemsonrails.rubyforge.org and Dr Nic Williams from where i got this information 


BASIC WORK

Link or freeze RubyGems into your rails apps, instead of just plugins. This allows you to ‘vendor everything’ – pushing all dependent gems into your rails app thus ensuring your application will be guaranteed to work when deployed. Your application is no longer dependent on the gems that are/aren’t available on your target deployment environment.


Installation and The Basics

First you install the gem:

$ sudo gem install gemsonrails
Then you deploy the gem into your target Rails application:

$ cd rails_app_folder
$ gemsonrails
This installs some rake tasks into your app to help you freeze or link gems:

$ rake -T | grep "gems:" 
rake gems:freeze    # Freeze a RubyGem into this Rails application; init.rb will be loaded on startup.
rake gems:link      # Link a RubyGem into this Rails application; init.rb will be loaded on startup.
rake gems:unfreeze  # Unfreeze/unlink a RubyGem from this Rails application
Finally, for each gem your application uses you can either freeze a  version into the app (only for gems that do not require native  compilation), or link a gem with your app (useful for gems that require  native compilation)

$ rake gems:freeze GEM=map_by_method
Unpacked map_by_method 0.6.0 to 'map_by_method-0.6.0'

$ ls vendor/gems/map_by_method-0.6.0/
CHANGELOG    README    Rakefile     init.rb      lib     test

$ cat vendor/gems/map_by_method-0.6.0/init.rb 
require File.join(File.dirname(__FILE__), 'lib', 'map_by_method')


Restricting which environments a gem is loaded into

You can restrict which RAILS_ENVs the gem will be loaded for, using ONLY; e.g.


$ rake gems:freeze GEM=<gemname> ONLY=development
$ rake gems:link GEM=<gemname> ONLY=production,staging
In the former, only in development mode will the gem be loaded. In the latter, only in production or staging mode will the gem be loaded from the deployment gem server

Upgrading from old GemsOnRails versions

All the freezing and linking functionality is in the plugin installed by the gemsonrails command. To upgrade, simple install the new gem version, and re-run the gemsonrails command. You application will now have the newest rake tasks and functionality.


Forum

http://groups.google.com/group/gemsonrails

How to submit patches

Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.

Licence

This code is free to use under the terms of the MIT licence.


Monday, 16 January 2012

Bort: Better Skeleton Applications


We’re all familiar with the rails command-line tool. It generates a Rails skeleton application with everything you need to start your Rails application–directories, configuration, even a default index page.
But the more you develop Rails applications, the more you begin to realize that some tools and gems are valuable on every project. Need a user management system? Likely restful_authentication. Rails pagination slow? Grab will_paginate. Even things like setting sessions to use the database, or using MySQL instead of sqlite3 as your database.





Enter bort. Bort is a replacement of the standard skeleton application; it includes these features (and more), already setup and configurated to work out-of-the-box. And it is a bigger box–it includes:
  • RESTful Authentication, for a RESTful user-management system (registering users, logging in, etc.). Even includes the forgotten password feature!
  • User Roles, to make your application users easier to manage; includes a default admin role and an admin user.
  • Will Paginate, an efficient, pretty pagination plugin. Beats the standard Rails pagination by ages!
  • OpenID integration, in case you want to support OpenID with your users.
  • Rspec, a better way to write tests.
  • Exception Notifier, to email you when your application hiccups.
  • Asset Packager, which combines javascript and CSS to save download time.
  • Database Sessions, MySQL DB YAML, an application-wide layout file, and no default index.html and rails.png, all of which make your life a little easier.
This is a big step up from your standard Rails skeleton. Best of all, if you don’t use half of this stuff, it won’t affect you much; and it’ll be there when you need it.

You can Grab bort from the GitHub page,
http://github.com/fudgestudios/bort

Friday, 13 January 2012

Rails "The MVC Architecture"


At the core of Rails is the Model, View, Controller architecture, usually just called MVC. MVC benefits include:
  • Isolation of business logic from the user interface
  • Ease of keeping code DRY
  • Making it clear where different types of code belong for easier maintenance

 Models

The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.

A model represents the information (data) of the application and the rules to manipulate that data. In the case of Rails, models are primarily used for managing the rules of interaction with a corresponding database table. In most cases, each table in your database will correspond to one model in your application. The bulk of your application’s business logic will be concentrated in the models.

 Views

The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A view port typically has a one to one correspondence with a display surface and knows how to render to it.

Views represent the user interface of your application. In Rails, views are often HTML files with embedded Ruby code that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.

Controllers

The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a view port to perform actions based on that input.

Controllers provide the “glue” between models and views. In Rails, controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.