You are here: Noosfero>Dev>Console (11 Jun 2013, AurelioAHeckert) EditAttach

Using the Noosfero Console

Starting the console in a Debian package installation

Just run the following command as root:

noosfero-console

With a regular user with sudo enabled, you can just run sudo noosfero-console.

You can skip the following section and go directly to Using the console.

Starting the console in a manual installation

In a terminal, change to the directory where Noosfero is installed. For example, if noosfero is installed in /home/you/noosfero:

cd /home/you/noosfero

To start the Noosfero console run:

script/console

By default, the console starts in the development environment. If you want to access production data, use:

script/console production

Using the console

The Noosfero console is the Ruby-on-Rails console. Like the irb, this console is a Ruby console, so any Ruby code will be directly executed, and the Noosfero base is pre-loaded, allowing you to create or change any data directly.

See a usage example to access data:

>> p = Person['batman']
>> p.friends.each {|f| puts f.name }
Robin
Alfred
Bat Girl

Changing data:

>> p1 = Person['batman']
>> p2 = Person['superman']
>> AddFriend.create!(:requestor => p1, :target => p2).finish

Changing object attributes require saving those objects in order to have your changes reflected in the database. Example:

>> p1 = Person['batman']
>> p1.email = 'batman@example.com'
>> p1.save!

If the save! call does not raise an exception, then everything is ok and that change is already persisted in the database.

All the entity types are classes and you may found the object instances by its methods, like the example done with the Person. Other examples are Community, User, Environment, ...

Environment.default gives you access the default environment (or the only one, if you don't created extra environments) and allows you to change the roles.

e = Environment.default
e.name = "The Cool Social Network"
e.save

Considerations about console usage on production data

  1. to start the console, make sure your shell is running under the same user as the Noosfero application servers. For example, if your applications servers run under the user "noosfero", then you must first become the user "noosfero" and then enter the console:
          $ sudo su - noosfero
          $ cd /path/to/noosfero
          $ script/console production
    (replace /path/to/noosfero with the actual path to your noosfero installation!)
  2. have in mind that you are changing production data, so be careful with what you do there!

Useful Console Usage


Add comment
You need to login to be able to comment.
 
Topic revision: r14 - 11 Jun 2013 - 13:05:14 - AurelioAHeckert
 
Translations: English
Search on Docs:
   
ActionItem Search:

Copyright © 2007-2014 by the Noosfero contributors
Colivre - Cooperativa de Tecnologias Livres