RUBY: Create an empty array and have array length


This will create an array with the 10 empty elements.

>> Array.new(10, '')
Output
=> ["", "", "", "", "", "", "", "", "", ""]
Continue Reading

PostgreSQL: Handling the sequence value in psql(Reset sequence/ Get sequence next value)

PostgreSQL: Reset the sequence value of the table

Example1

select setval('students_id_seq',1706);

Result

  setval
--------
   1706
(1 row)

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

Example2(Recommanded)

To reset the sequence exactly to the recent primarykey id. This is the best idea to reset the sequence by avoiding usual conflicts.

select setval('students_id_seq',(select max(id) from students)) 

Result

  setval
--------
   1706
(1 row)

 

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

PostgreSQL: Get the next sequence value of the table

select nextval('students_id_seq');

Result

 nextval
---------
    1707
(1 row)

Continue Reading

RUBY: Easy to create first controller in ruby on rails

Create new controller in ruby on rails is the easy thing. Just follow the following process

[root]# script/generate controller <controller-name>

Sample
script/generate controller registration

this will genereate the following folders/files.

      exists  app/controllers/
      exists  app/helpers/
      create  app/views/registration
      exists  test/functional/
      create  app/controllers/registration_controller.rb
      create  test/functional/registration_controller_test.rb
      create  app/helpers/registration_helper.rb
Continue Reading