Wednesday, 25 January 2012

Rails Blog with Scaffolding

I think you have installed ruby and Rails correctly.

Otherwise please visit this links:
Click Here

then follow the steps:
To make a new application, all we do is "Rails new 'Our app name'".
The name of this application will be webblog.


$ rails new webblog


This will put the directory 'webblog' on our desktop with all the necessary structures already built inside.

Now we will remake our current directory webblog.

$ cd webblog

The next thing we will do is now generate the scaffold of our blog. This is why scaling rails applications is soo easy.

$ rails generate scaffold Blog title:string content:text
$ rake db:migrate
$ rm public/index.html


The first line will generate the application from the front-end to the backend. It's a pretty simple configuration that you can edit upon to really make 'better'. Then next line migrates the database to add the database table for the blog entries, and the last line gets rid of the default page when you open up localhost:3000.

Now we must go into config/routes.rb and edit the root directory. Add this code to your routes.
App::Application.routes.draw do
  resources :posts

  root :to => "blog#index"
end

Now go back to the command line to fire this code.

$ rails server

This will fire up the server to start your rails application. Now you have created a small 5 minute scaffolded Rails blog. Hope this get's you started up

Ruby on Rails installation in ubuntu 11.10

This should be an obvious one. Make sure your distribution is up to date.

sudo apt-get update
sudo apt-get upgrade

Installing RVM
Grab curl and git

sudo apt-get install git curl

Install Ruby Version Manager (RVM).

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm); 
Then we need to add the environment variables to our .bashrc file.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc;

We need to reload the .bashrc, so let us source it.

source ~/.bashrc;

Installing Necessary Libraries

sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf;

Installing Ruby
Now the fun part, installing Ruby. Assuming you have sourced your .bashrc file we will be able to install Ruby

If you want 1.9.2 do the following

rvm install 1.9.2

If you want both, just execute both commands. You are allowed to install as many different versions of Ruby that you want.

Say I want to set 1.9.2 to always be my default when I open a terminal. No problem

rvm --default use 1.9.2

Install all of the essential libraries for Ruby to work.
Installing a MySQL Server

Installing a MySQL server is pretty easy. Just run:

sudo apt-get install mysql-server libmysql-ruby libmysqlclient-dev;

The last two libraries are for the mysql and mysql2 gems to communicate with the local server.
Installing Gems

I highly recommend using gemsets to develop Rails applications with. This is so that you do not screw multiple applications up because you are using different gems and you didn’t want to update a specific gem for a specific application.

All in all, it will reduce headaches, so use it.

To create a gemset

rvm gemset create project

To use a gemset

rvm gemset use project

It is that easy. Use them, love them, live with them. I am developing two different Rails applications that use different versions of Rails and Ruby. Talk about a headache if you weren’t using RVM.
Install Rails

Assuming you have selected the gemset you want to use, let us install Rails

gem install rails

After this point you can create your Rails application like you normally would.
Getting Rails To Interact With MySQL

I had been developing with SQLite3 for a while and figured the smarter route would be to just go ahead an use MySQL

gem install mysql2

Default (sqlite3 backend):

rails /home/myuser/www/first_app

For a mysql back-end. Run this one, if you installed rails with gem:

rails /home/myuser/www/first_app -d mysql

Run this one, if you installed rails with apt:


rails /home/myuser/www/first_app -D mysql

$ mkdir rails_projects
$ cd rails_projects
$ rails new first_app

After creating a new Rails application, the next step is to use Bundler to install and include the gems needed by the app. This involves opening the Gemfile with your favorite text editor:


$ cd first_app/
$ gedit Gemfile

The default Gemfile in the first_app directory.

source 'http://rubygems.org'

gem 'rails', '3.0.11'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri', '1.4.1'
# gem 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for certain environments:
# gem 'rspec', :group => :test
# group :test do
# gem 'webrat'
# end

changes This line

gem 'sqlite3'

To

gem 'sqlite3', '1.3.3'

If you’re running Ubuntu Linux, you might have to install a couple of other packages at this point


$ sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev 
# Linux only

Once you’ve assembled the proper Gemfile, install the gems using bundle install

In Ruby 1.9.2 dont have those packages are included. So
In your Gemfile write this

gem 'execjs'
gem 'therubyracer'

and then run

bundle install

Fetching source index for http://rubygems.org/
.
.
.

cd first_app
rails server

Now open your browser and type the following address in the address bar -

http://localhost:3000

That’s All..now you are ready to ‘Ruby on Rails’ create new Application using simple command and start the server.

Tuesday, 24 January 2012

Installing Ruby support in NetBeans 7.0 Beta 2

NetBeans 7.0 Beta 2 is the first release where Ruby and Rails support does not show up as an available plugin choice. Until we have our first community release, you can follow these steps to update your plugins list so you can still add Ruby support to NB 7 Beta 2:
  1. Click Tools -> Plugins
  2. Click on 'Settings' tab
  3. Click on 'Add' button to get Update Center Customizer popup
  4. Set name to 'Beta 1'
  5. Set URL: to 'http://updates.netbeans.org/netbeans/updates/7.0/uc/beta/stable/catalog.xml.gz'
  6. Press 'OK'
  7. Click to 'Available Plugins'
  8. Click 'Reload Catalog'
  9. Choose 'Ruby and Rails'
  10. Pat yourself on the back
It appears that adding the first beta's stable catalog does not confuse the 2nd beta's list. With any luck we will have a community release which is easier to install by the time NetBeans reaches 7.0 final

Thursday, 5 January 2012

jQuery Looped Slider Tutorial

Today we’re going to use Nathan Searles’ jQuery loopedSlider, a plugin made for jQuery that solves a simple problem, the looping of slide content. It was created to be easy to implement, smooth and most of all end the “content rewind” that most other content sliders suffer from.
This is going to be a quick and easy tutorial. You can just copy and paste the code and have yourself a looping slider in minutes. You can view a working demo and feel free to download the complete source files.

Markup

view plaincopy to clipboardprint?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
  •     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  •   
  • <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
  • <head>  
  •     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
  •   
  •     <title>loopedSlider jQuery Plugin</title>  
  •   
  •     <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>  
  •     <script src="loopedslider.js" type="text/javascript" charset="utf-8"></script>  
  •   
  •     <style type="text/css" media="screen">      
  •   
  •     </style>  
  • </head>  
  •   
  • <body>  
  • <div id="loopedSlider">  
  •     <div class="container">  
  •         <div class="slides">  
  •             <div><img src="image-01.jpg" width="600" height="393" alt="First Image" /></div>  
  •             <div><img src="image-02.jpg" width="600" height="393" alt="Second Image" /></div>  
  •             <div><img src="image-03.jpg" width="600" height="393" alt="Third Image" /></div>  
  •             <div><img src="image-04.jpg" width="600" height="393" alt="Fourth Image" /></div>  
  •         </div>  
  •     </div>  
  •     <a href="#" class="previous">previous</a>  
  •     <a href="#" class="next">next</a>  
  •     <ul class="pagination">  
  •         <li><a href="#">1</a></li>  
  •         <li><a href="#">2</a></li>  
  •         <li><a href="#">3</a></li>  
  •         <li><a href="#">4</a></li>  
  •     </ul>  
  • </div>  
  • </body>  
  • </html>  

Styles (CSS)

  • /* 
  •  * Required 
  • */  
  • .container { width:600pxheight:393pxoverflow:hiddenposition:relativecursor:pointer; }  
  • .slides { position:absolutetop:0; left:0; }  
  • .slides div { position:absolutetop:0; width:600pxdisplay:none; }  
  • /* 
  •  * Optional 
  • */  
  • #loopedSlider,#newsSlider { margin:0 autowidth:500pxposition:relativeclear:both; }  
  • ul.pagination { list-style:nonepadding:0; margin:0; }  
  • ul.pagination li  { float:left; }  
  • ul.pagination li a { padding:2px 4px; }  
  • ul.pagination li.active a { background:bluecolor:white; }  

Power Up The Slider

This time we’re going to initialize the plugin from the bottom section of our document in order to load our content first before the calling our plugin.
  • <script type="text/javascript" charset="utf-8">  
  •     $(function(){  
  •         $('#loopedSlider').loopedSlider();  
  •     });  
  • </script>  
  • </body>  
  • </html>  
Autostart the slider:
  • <script type="text/javascript" charset="utf-8">  
  •     $(function(){  
  •         $('#loopedSlider').loopedSlider({  
  •             autoStart: 3000  
  •         });  
  •     });  
  • </script>  
  • </body>  
  • </html>  
Initialize multiple sliders:
  • <script type="text/javascript" charset="utf-8">  
  •     $(function(){  
  •         $('#loopedSlider').loopedSlider({  
  •             autoStart: 3000  
  •         });  
  •         $('#anotherSlider').loopedSlider({  
  •             autoHeight: 400  
  •         });  
  •     });  
  • </script>  
  • </body>  
  • </html>

Drupal 7 node_load references

// Load up the node with files on it.
$node = node_load(1);
 
// Render the node.
$rendered = node_view($node);
 
// Later, decide you want a 'fresh' copy of the node.
$fresh_node = node_load(1);
 
// Save the fresh node.
node_save($fresh_node);
Now go and edit your file in Drupal, where has your uploaded file gone?
Well, the call to node_view means that file.module directly unsets the files that shouldn't be displayed. But, in my code, this node is effectively global, so when I call my second node load, it's not 'fresh' at all, I just get back a reference to the node that's had the file removed, so calling node_save on it was a very bad idea.

$query = new EntityFieldQuery;
$result = $query
  ->entityCondition('entity_type', 'node')
  ->propertyCondition('type', 'mytype')
  ->propertyCondition('title', $text)
  ->execute();

if (!empty($result['node'])) {
  $nodes = node_load_multiple(array_keys($result['node']));
  echo current($nodes)->body['und'][0]['safe_value'];
}

 $nid = $rs->nid;
  $node = node_load($nid);

 <?php print $node->body['und'][0]['value'];?>
 
 

Source base installation of php, mysql and apache in ubuntu/ linux

Compile and Install a LAMP(Linux/Apache/MySQL/PHP) Server from Source In the last post, I described the method to install a LAMP ser...