Bonjour,
j'essaie d'apprendre par moi même la programmation Ruby on Rails.
En suivant un tuto j'ai fait un mini projet bateau qui a deux tables : articles et commentaires, un controller et deux vues.
lorsque j'appelles mon projet depuis mon navigateur ça fonctionne jusqu'au moment où j'essaies d'ajouter un article. A ce moment j'ai cette erreur :
voici mon controller :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]
je me suis contenté (pour l'instant) de copier le tuto pour voir comment ça fonctionne et essayer de comprendre....je n'ai fait que commenter le render_action car sinon j'avais une erreur undefined method
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 class MonsiteController < ApplicationController def index listeArticle # render_action "listeArticle" end def listeArticle @articles= Article.find(:all, :order => "created_at DESC", :limit => 5) end def ajoutArticle article= Article.new(@params["article"]) if article.save flash[:ok]= "article ajouté" else flash[:error]= "erreur d'ajout" end redirect_to :action => "listeArticle" end def afficheArticle @notes=[] 11.times do |note| @notes.push(note) end @article= Article.find_by_id(@params["id"]) end def ajoutCommentaire comment= Commentaire.new(@params["commentaire"]) comment.article= Article.find_by_id(@params["articleid"]) if comment.save flash[:ok]= "commentaire ajouté" else flash[:error]= "erreur d'ajout" end redirect_to :action => "afficheArticle", :id => comment.article.id end end
pourriez-vous m'aider sur cette erreur ("You have a nil....") svp ??
merci d'avance
Partager