Jan 172013
 

I’m using devise and I still not know when exactly stopped working the sign_out, but at some point the route

http://localhost:3000/users/sign_out

gave a routing error. For the moment, until I can really understand why is not working any more, I found some solution in a forum (lost the link, sorry :-/), where someone had posted the same problem.

So here is the solution, to overwrite the DELETE method with the GET method, so you need to add to the routes.rb file the following line:

devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end

Now the users can log out!!!

 Posted by at 12:19 pm
Jan 172013
 

After doing a merge between branches I got an error, that I was not sure why was there.
The error was on the acts_as_taggable_on fields

Failures:

1) GET /cycles display cycles
Failure/Error: visit cycles_path
ActionView::Template::Error:
PG::Error: ERROR: relation "tags" does not exist
LINE 4: WHERE a.attrelid = '"tags"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"tags"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

I tried different things that didn’t work until I thought about reseting the database

$ rake db:reset RAILS_ENV=test

Once I did it, everything worked again :-)

 Posted by at 4:06 am
Dec 062012
 

With a lot of delay a post what was our second day with this pet app, since then we have done a lot of things, that somehow I’ll try to post in following days.

We create the relation between models
We begin adding the relation that implies that one location can have many events but one events is in one location

we edit the model event.rb and add

belongs_to: location

then we open model location.rb and all
has_many: events

then we proceed with events and categories, which have a relation where one event can have many categories and one category many events associated

Edit event.rb and add

has_many: categories
has_and_belongs_to_many: categories

edit category.rb and add
has_and_belongs_to_many: events

Now we are going to introduce in the console the first data to check if the relations are ok
We create an event with just name

Event.create :name => "Rails girls at CBase", :date =>"2012-11-11"

Continue reading »

 Posted by at 4:00 am
Nov 232012
 

Después de perder dos mañana intentando configurarme el postgres para poder usarlo desde Rails,  encontrarme con fallos y la solución atravesarse un poco, pues cuento cómo se ha solucionado y si alguien se ahorra el tiempo pues mejor que mejor.

Básicamente he seguido esta guía para la instalación y configuración en Ubuntu

Primero hay que instalarse el postgres en Ubuntu
sudo apt-get install postgresql

En mi caso me he saltado la parte relacionada con la configuración de PostgreSQL para permitir conexiones vía TCP/IP, así que paso directamente a crear un usuario.

Crear usuario
Vamos a la terminal y escribimos
$sudo -u postgres createuser

Enter name of role to add: USUARIO
Shall the new role be a superuser? (y/n) y
CREATE ROLE

Después creamos la base de datos de PostgreSQL
Usamos el comando createdb para crear la base de datos

$sudo -u postgres createdb NOMBRE_BASE_DE_DATOS
CREATE DATABASE

Damos permisos al usuario para acceder a la base de datos
Por último, vamos a ponerle contraseña al usuario de postgres y darle los permisos

$sudo -u postgres psql
postgres=# alter user USUARIO with encrypted password ‘password’;
ALTER ROLE
postgres=# grant all privileges on database NOMBRE_BASE_DE_DATOS to USUARIO;
GRANT

Ahora vamos a instalar el cliente de postgresql
$sudo apt-get install postgresql-client

Ahora vamos a comprobar que todo ha ido bien y te puedes conectar a tu base de datos con el usuario definido

psql -h localhost

Hasta ahí todo iba bien, pero luego me iba a mi aplicación rails, hacía

$rake db:migrate

y me devolvía el siguiente error

FATAL: Peer authentication failed for user XXXX

Así que después de volverme un poco loca, porque no conseguía resolverlo y pese a que en varios post ponían aproximaciones a la solución, pues no era completo (o al menos no lo entendía así)

Editamos el fichero /etc/postgresql/9.1/main/pg_hba.conf

Y cambiamos todas las referencias a “peer” por “md5″, en las líneas que no están comentadas en el fichero, de manera que el fichero de configuración debe quedar de la siguiente manera:

# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
#local all postgres peer
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD

# “local” is for Unix domain socket connections only
#local all all peer
local all all md5
# IPv4 local connections:

#host all all 127.0.0.1/32 md5
host all all 127.0.0.1/32 md5

# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
(END)

Luego reiniciamos el postgres

$sudo /etc/init.d/postgresql restart

Y ya debería estar todo preparado y funcionando para crear tus migraciones en la aplicación rails :-)

 Posted by at 9:32 am
Nov 122012
 

Several times I’ve found out that my rails console didn’t work, not really sure why but I guess that is when there is a certain update in the Ubuntu. The versions of the software are ruby 1.9.3, rails 3.2.8 and rvm 1.14.11

I’m in my projects directory/folder, in my case that is

sonduk@sonduk:~/reposrails/stress-faktor

remember that while reading this post
So what happens is

$ rails c
/home/sonduk/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError)
from /home/sonduk/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
from /home/sonduk/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:3:in `require'
from /home/sonduk/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:3:in `<top (required)>'
from /home/sonduk/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:38:in `require'
from /home/sonduk/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:38:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

So to making the rails console work again, this is what I’ve done:

Since I’m using rvm, first I check the requirements, with

$ rvm requirements

Continue reading »

 Posted by at 10:19 am