Undefined method `title' for nil:NilClass => erreur SMTP?

Bonjour à tous,
j’ai une application rails développé par eclipse. A un moment
l’application beug et me renvoi un message d’erreur undefined method
title' for nil:NilClass En regardant un peu mieux les log je vois ces 2 lignes : P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/associations/association_proxy.rb:125:insend’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/associations/association_proxy.rb:125:in
method_missing' /app/models/update.rb:43:indo_update’

qui semble indiqué qu’il s’agit d’un problème smtp. Pourtant, comme je
suis sur un environnement de test j’ai ajouté l’instruction qui permet
de ne pas utiliser de serveur SMTP
config.action_mailer.delivery_method = :test

Auriez vous une idée du problème ?

2009/4/10 Angelo [email protected]

method_missing' /app/models/update.rb:43:in do_update’

le problème, c’est que tu ne donnes pas de code dans ton message, et
comme
ma boule de crystal est en révision, pas moyen de te répondre. C’est
ballot,
non?
Pour info, rien ne parle de SMTP pour l’instant.

bonjour,
Un problème smtp a bon, pourquoi ? je vois pas le smtp ???

sinon tu as pas un object avec un champ title…

2009/4/10 Angelo [email protected]

Une remarque si je peux me permettre ton modèle s’appelle ‘update’ …
avec
une fonction ‘do_update’.je sais pas trop, mais moi j’évite les noms qui
pourrait rentrer en conflit avec des méthodes…

2009/4/10 Cyril M. [email protected]

Angelo wrote:

/app/models/update.rb:43:in `do_update’

qui semble indiqué qu’il s’agit d’un problème smtp. Pourtant, comme je
suis sur un environnement de test j’ai ajouté l’instruction qui permet
de ne pas utiliser de serveur SMTP
config.action_mailer.delivery_method = :test

Auriez vous une idée du problème ?
ligne 43 de ton model tu appeles la méthode .title sur un objet qui est
en fait nil. Tu devais surement le crois non nil sauf que parfois il est
nil.

Par contre j’avoue que je le coup du SMTP, je la recherche encore
longtemps. Un proxy n’a rien a voir avec du SMTP. c’est juste un
pattern.


Cyril M.

Bonjour et merci à tous de votre participation
Si j’ai affirmé qu’il s’agissait d’une erreur SMTP c’est que celui ci
m’a posé d’énorme problème et donc je me méfie maintenant !
Sinon comme je l’ai dis, je ne suis pas le créateur de cette
application ; mon rôle devait se réduire uniquement à son installation
(j’ai très très peu de notion de ruby)
comme vous m’avez parlez de la méthode do_update je vous la montre (si
ça peut aider)

def do_update
logger.info(“Doing update of #{self.wiki.title} with #
{self.baseline_process.title}”)
if self.first_update?
Notifier::deliver_site_status(self, “STARTED creating New Wiki #
{self.wiki.title} using Baseline Process #
{self.baseline_process.title}”)
self.wiki.wikify(self)
Notifier::deliver_site_status(self, “FINISHED creating new Wiki #
{self.wiki.title} using Baseline Process #
{self.baseline_process.title}”)
else
Notifier::deliver_site_status(self, “STARTED update of Wiki #
{self.wiki.title} with Baseline Process #
{self.baseline_process.title}”)
self.wiki.update_wiki(self)
Notifier::deliver_site_status(self, “FINISHED update of Wiki #
{self.wiki.title} with Baseline Process #
{self.baseline_process.title}”)
end
self.finished_on = Time.now
self.save!
users = User.find(:all, :conditions => [‘notify_immediate=?’, 1])
unless users.empty?
subject = “Wiki #{self.wiki.title} Updated with Baseline
Process #{self.baseline_process.title}”
introduction = “User #{self.user.name} updated Wiki <a href=
"http://#{self.wiki.url(true)}">#{self.wiki.title} with Baseline
Process #{self.baseline_process.title}.”
Notifier::deliver_notification(users,subject,introduction,
nil)
end
expire_all_pages
# Notify contributors of harvested stuff
contributions = Upload.find(:all, :conditions => [‘done=? and
review_note_send_on is null’, ‘Y’]) +
Comment.find(:all, :conditions => [‘done=? and
review_note_send_on is null and site_id=?’, ‘Y’, self.wiki.id]) +
UserVersion.find(:all, :conditions => [‘done=? and
review_note_send_on is null and wiki_id=?’, ‘Y’, self.wiki.id])
contributions.collect{|rec|rec.user}.uniq.each do |u |
Notifier::deliver_contributions_processed(u,
contributions.collect{|rec|rec if rec.user == u}.compact)
end
contributions.each do |record|
record.review_note_send_on = Time.now
record.save!
end
end

On 10 avr, 15:50, guillaume belleguic [email protected]

Excusez moi , j’ai tellement eu de problème avec ce serveur SMTP que
la moindre contrariété, je lui attribue
J’aimerai donner du code mais moi même j’ignore où se trouve
exactement le problème (comme je l’ai dis l’application est développé
par eclipse et surtout je ne connais pas le ruby => en principe
j’étais pas sensé mettre mon nez dedans, juste l’installer via la
procédure)

Je peux vous mettre la totalité du log pour que vous m’indiquiez le
problème ou du moins où il se situe …
NoMethodError (undefined method title' for nil:NilClass): /app/models/wiki.rb:118:in update_wiki’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/associations/association_proxy.rb:125:in send' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/associations/association_proxy.rb:125:in method_missing’
/app/models/update.rb:43:in do_update' /app/controllers/sites_controller.rb:105:in update_now’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:1158:in send' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:1158:in perform_action_without_filters’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:697:in call_filters' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:725:in run_before_filters’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:664:in call' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:664:in proxy_before_and_after_filter’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:483:in call' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:483:in call’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:722:in run_before_filters' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:695:in call_filters’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:689:in perform_action_without_benchmark' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/benchmarking.rb:68:in perform_action_without_rescue’
P:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/benchmarking.rb:68:in perform_action_without_rescue’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/rescue.rb:199:in perform_action_without_caching' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/caching.rb:678:in perform_action’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/connection_adapters/abstract/query_cache.rb:33:in
cache' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/query_cache.rb:8:in cache’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/caching.rb:677:in perform_action' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:524:in send’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:524:in process_without_filters' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:685:in process_without_session_management_support’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/session_management.rb:123:in process' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:388:in process’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:171:in handle_request' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:115:in dispatch’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:126:in dispatch_cgi' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:9:in dispatch’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/…/lib/mongrel/rails.rb:76:in process' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel/rails.rb:74:in synchronize’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/…/lib/mongrel/rails.rb:74:in process' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel.rb:159:in process_client’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/…/lib/mongrel.rb:158:in each' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel.rb:158:in process_client’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/…/lib/mongrel.rb:285:in run' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel.rb:285:in initialize’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/…/lib/mongrel.rb:285:in new' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel.rb:285:in run’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/…/lib/mongrel.rb:268:in initialize' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel.rb:268:in new’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/…/lib/mongrel.rb:268:in run' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel/configurator.rb:282:in run’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/…/lib/mongrel/configurator.rb:281:in each' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel/configurator.rb:281:in run’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/mongrel_rails:128:in run' P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/ bin/../lib/mongrel/command.rb:212:in run’
P:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/
bin/mongrel_rails:281
P:/INSTAN~1/ruby/bin/mongrel_rails:19:in `load’
P:/INSTAN~1/ruby/bin/mongrel_rails:19

On 10 avr, 15:36, guillaume belleguic [email protected]

2009/4/10 Angelo [email protected]

Excusez moi , j’ai tellement eu de problème avec ce serveur SMTP que
la moindre contrariété, je lui attribue
J’aimerai donner du code mais moi même j’ignore où se trouve
exactement le problème (comme je l’ai dis l’application est développé
par eclipse et surtout je ne connais pas le ruby => en principe
j’étais pas sensé mettre mon nez dedans, juste l’installer via la
procédure)

Moi c’est mon plus jeune chat qui me pose problème, mais je lui attribue
pas
mes boulettes, tout comme ce n’est pas mon vim qui développe mes projets
tout seul…

Balance ton fichier /app/models/wiki.rb autour de la ligne 118, sinon
on ne
peut pas faire de divination, mais je devine que c’est un problème de
base
vide, avec un contrôleur mal blindé.

Oui certes …

Pour mon fichier wiki.rb, voici la méthode update_wiki (c’est un peu
long)
def update_wiki(update)
update.update_attributes(:started_on => Time.now)
bp = update.baseline_process
logger.info(“Starting update of wiki #{self.title} from baseline
process #{self.baseline_process.title} (#{self.baseline_process.id})
to #{bp.title} (#{bp.id})”)
logger.info("Copy update site " + bp.path + " to " + self.path)
cadmin = User.find_central_admin
# 1.
bp.copy_to(self, nil)
# 2. Update status of EPFC pages to ‘undetermined’
Page.update_all( “status = ‘Undetermined’”, ["tool = ? and site_id
= ? ", ‘EPFC’, self.id, ])
# 3. Update
bp.scan4content if bp.content_scanned_on.nil?
bp.pages.each do |p|
page = Page.find_by_site_id_and_rel_path(self.id, p.rel_path)
if page
page.status = ‘Updated’
no = page.max_version_no + 1
else
page = WikiPage.new(:rel_path => p.rel_path, :site =>
self, :tool => ‘EPFC’, :status => ‘New’, :site_id => self.id)
no = 0
end
# create baseversion
baseversion = BaselineProcessVersion.new(:baseline_update =>
update,:user => cadmin, :page => page,
:wiki => self, :version => no, :done =>
‘Y’, :note => ‘Automatically created’,
:baseline_process_id => bp.id)
page.baseline_process_versions << baseversion
page.save!
end
# 4.
Page.find(:all, :conditions => [‘site_id = ? and status = ?’,
self.id, ‘Undetermined’]).each do |p|
p.status = ‘RemovedOrMoved’
p.save!
end
# 5.
Page.find(:all, :conditions => [‘site_id = ? and tool = ?’,
self.id, ‘Wiki’]).each do |p|
if p.harvested?
p.status = ‘Harvested’
end
end
# 6.
enhance_files
# Change 68 - current versions not harvested
versions = UserVersion.find(:all, :conditions => [‘wiki_id =? and
done <> ? and version is not null’, self.id, ‘Y’])
logger.info(“Found #{versions.size.to_s} versions with unharvested
changes”)
pages = versions.collect{|version| version.page}.uniq
if pages
logger.info(“Found #{pages.size.to_s} pages with unharvested
changes”) if pages
snippets = Page.get_snippets
pages.each do |page|
logger.info(“Processing page #{page.presentation_name}”)
if page.checkout
logger.info(“Page has unharvested versions, we don’t need to
set a current version”)
else
cv = page.current_version
unless cv.nil?
if cv.current
logger.info(“Page #{page.presentation_name} already has
current version with id #{cv.id}, we don’t need to set a current
version”)
else
logger.info(“Page #{page.presentation_name} does not
have a current version”)
# set the current version equal to the last version that
is not part of the update we are doing
page.current_version = Version.find(:first, :order =>
‘version DESC’, :conditions => [‘page_id=? and version is not null and
update_id is null’,page.id])
end
page.html = page.current_version.html
Page.enhance_file(page.path, snippets)
end
end
end
end
self.baseline_updated_on = Time.now
self.baseline_process = bp
self.save!
end

Angelo wrote:

Excusez moi , j’ai tellement eu de problème avec ce serveur SMTP que
la moindre contrariété, je lui attribue
J’aimerai donner du code mais moi même j’ignore où se trouve
exactement le problème (comme je l’ai dis l’application est développé
par eclipse
Il faut demander à Eclipse d’arreter de faire du code ruby buggé :slight_smile:


Cyril M.

Angelo wrote:

Excusez moi , j’ai tellement eu de problème avec ce serveur SMTP que
la moindre contrariété, je lui attribue
J’aimerai donner du code mais moi même j’ignore où se trouve
exactement le problème (comme je l’ai dis l’application est développé
par eclipse et surtout je ne connais pas le ruby => en principe
j’étais pas sensé mettre mon nez dedans, juste l’installer via la
procédure)

Je peux vous mettre la totalité du log pour que vous m’indiquiez le
problème ou du moins où il se situe …

Comme dis précédement :

/app/models/update.rb:43:in `do_update’

Voici la seule ligne qui te suffit et où se trouve la ligne. Ton log ne
donne pas les lignes :slight_smile:


Cyril M.

Bon j’ai repris à zéro l’installation
et il semblerait que l’erreur ne soit pas dans le script mais c’était
un problème d’insertion de donnée dans la base
Après avoir détruit la base, puis la recréée et modifier les données
qui posaient problème l’application fonctionne :slight_smile:

Le 10 avril 2009 16:31, Cyril M. [email protected] a écrit :

Comme dis précédement :

/app/models/update.rb:43:in `do_update’

Voici la seule ligne qui te suffit et où se trouve la ligne.

Non, je suis plutôt d’accord avec ook? c’est dans Wiki#update_wiki

Ton log ne donne pas les lignes :slight_smile:

Visiblement on a :

Update < AR::B, BaselineProcess < AR::B, Wiki < AR::B
Update.belongs_to :wiki, Update.belongs_to :wiki
BaselineProcess.belongs_to :wiki

Update#do_update appelle (via un proxy, mais ça importe peu)
la méthode Wiki#update_wiki

Au début de la méthode, on a :

bp = update.baseline_process
logger.info(“Starting update of wiki #{self.title} from baseline
process #{self.baseline_process.title} (#{self.baseline_process.id})
to #{bp.title} (#{bp.id})”)

soit bp = update.baseline_process vaut nil
ou self.baseline_process vaut nil.

Du coup la ligne 118 serait l’appel au logger.

Ceci dit, dans Update#do_update, avant d’arriver
à la ligne :

self.wiki.update_wiki(self)

…il y a déjà des self.baseline_process.title et self.wiki.title
qui passent bien. Ce qui voudrait dire que l’association
Update → BaselineProcess est ok, Update → Wiki est ok,
mais pas Wiki → BaselineProcess

Donc l’erreur proviendrait de :

self.baseline_process.title dans Wiki#update_wiki dans le
logger.info(…)
précédemment
cité.
À part ça, je suis d’accord avec Guillaume, appeler un modèle Update
est une très mauvaise idée, tu as Wiki.has_many :updates
donc tu fais des wiki.updates, mais ça ressemble trop
à AR::B#update, c’est un truc à se faire avoir un de ces 4,
d’ailleurs quand on voit le code avec des :

update.update_attributes()

Ceci dit, on peut dire que le code est globalement affreux.

– Jean-François.


http://twitter.com/underflow_