Wednesday 30 April 2014

AUTHENTICATION USING DEVISE GEM

AUTHENTICATION USING DEVISE GEM

1, create a new application (Here my application name is deviseauth).

2, Remove index file from public and set the root file, (Here my root file is    
root :to => 'posts#home')

3, Add below statement to Gemfile.
gem 'devise'

4, Run $bundle install command.

5, Run $rails generate devise:install
     The generator will install an initializer which describes ALL Devise's configuration options and you M,UST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator.

6, $rails generate devise MODELNAME
    $rails generate devise user #Here user is modelname

7, Next u vil usally run $rake db:migrate

8, Add below filter to application_contoller.rb
  before_filter :authenticate_user!

9, Run the server
 $ rails s
10, Open localhost:3000 in ur browser u vill get below output.


11, to allow flash messages paste the below code in /layouts/application.html.erb
       <p class="notice"><%= notice %></p>
        <p class="alert"><%= alert %></p>

current_user.email:

The current signed-in user email.

code in view:
Welcome <%= current_user.email %> !!!

user_signed_in?:

To verify if a user is signed in, use the above helper. Returns true/false.

SESSION EXPIRING:

user.rb

class User
 devise  :timeoutable
 def timeout_in
   1.minutes
  end
end

SIGN OUT:

 <%= link_to "Sign Out",destroy_user_session_path,:method => :delete if user_signed_in? %>


Monday 21 April 2014

RAILS3 APPLICATION DEVELOPMENT STEPS


RAILS3 APPLICATION DEVELOPMENT STEPS


Step1: choose your rvm version and related gemset by issue below command.
$rvm use [rvmname]@[gemsetname]
ex: $rvm use 1.9.3@fb
then, your application going to use ruby 1.9.3 with gemset fb

Step 2: create a new application.
$rails new [appln name]
ex:$rails new myapp


Step3: uncomment line  NO 18 in myapp/Gemfile (gem 'therubyracer', :platforms => :ruby)

Step4: install the bundle

$bundle install

it will install all the gems specified in the gemfile.

Step5:run the server
$rails s (run with default port number 3000)
(or)
$rails s -p [portnumber]
Ex: $rails s -p 4000 (run with port 4000 )
 
Step 6: go to browser try to open localhost:3000

it will show fallowing output:
 
Step 7: Remove  myapp/public/index.html.erb page.
Step 8: create your own models/controllers using below commands.
  • To generate models,controller and views.
        $rails g scaffold [modelname singulur]
  • To generate only controller.
        $rails g controller [contollername] 
  • to generate only model. 
        $rails g model [modelname]
Ex: $rails g scaffold home
Step 8: add below line to myapp/config/routes.rb file.
$root :to => 'home#index'
Step 10: run your application on browser myapp/views/home/index is your home page.

Happy Reading...........:-)







SELECT_TAG DIFFERENT FORMS

  select tag 

syntax:

select_tag(name, option_tags = nil, options = {})

different forms of select_tag:

1, <%= select_tag :qual, options_for_select([["BE",1],["B.TECH",2],["ME",3],["M.TECH",4],["BSC",5]]), {:multiple=>true} %>

2,<%= select_tag :qual, options_for_select([["BE",1],["B.TECH",2],["ME",3],["M.TECH",4],["BSC",5]]), { include_blank: true }%>
 
3,
<%= select_tag :qual, options_for_select([["BE",1],["B.TECH",2],["ME",3],["M.TECH",4],["BSC",5]]), { :prompt => 'please select' }%>


 output: (1,2,3 outputs in sequence)

explanation: 

OPTIONS:

  1. :multiple - If set to true the selection will allow multiple choices.  
  2. :disabled - If set to true, the user will not be able to use this input.  
  3. :include_blank - If set to true, an empty option will be created. 
  4. :prompt - Create a prompt option with blank value and the text

Select In edit page: to get previous values

<%= f.select :genre, options_for_select([["Comedy",:Comedy],["Love",:Love],["Message",:Message],["Photography",:Photography],["Romantic",:Romantic],["Entertainment",:Entertainment],["Demo Oriented",:Demo],["Documentaries",:Documentaries],["Others",:Others]], @marketing.genre),{},{:class=>"multiselect",:multiple => true}%>

Wednesday 16 April 2014

RVM INSTALLATION IN UBUNTU


RVM INSTALLATION IN UBUNTU 13

Step 1:The first step is to install some dependencies for Ruby.
$sudo apt-get update
step 2:
$ sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config libgdbm-dev libffi-dev libreadline-dev
step3: Then, run the installer:
$ curl -L https://get.rvm.io | bash -s stable
step4:Make rvm acessible to your enviroment:
$ echo ‘source ~/.rvm/scripts/rvm’ » ~/.bash_aliases && bash
step 5:To check rvm requirements
$ rvm requirements
step 6: Install Ruby 1.9.3:
$ rvm install 1.9.3
step 7:Make 1.9.3 the default version:
$ rvm use 1.9.3 –default
step 8**:And, finally, rails:
$ gem install rails 
 TO GIVE ALIAS NAME FOR RVM
$rvm alias create [newname] [rvm version]
EX:$rvm alias create latest ruby-2.0.0-p247