Salut,
Je viens d'essayer le tutoriel http://www.netbeans.org/kb/60/ruby/getting-started.html en modifiant les champs (body et title =>nom, prenom, numero, adresse, cp, ville, tel, email) . Je commence a mieux comprendre le principe, la séparation des tâches entre controleur, modèle...
Par contre, j'ai quelques problèmes avec "respond_to" (dans le fichier posts_controller.rb) . Je ne comprends pas bien le principe.
Du coup, dans ma page principale index.html, je ne comprends pas d'ou sortent le edit_post_path(post) et le new_post_path ?
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 class PostsController < ApplicationController # GET /posts # GET /posts.xml def index @posts = Post.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @posts } end end # GET /posts/1 # GET /posts/1.xml def show #URL DE LA FORME /posts/id #Nom du modele.parametre(id) #alors => donne page #associer action truc... @post = Post.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @post } end end # GET /posts/new # GET /posts/new.xml def new @post = Post.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @post } end end # GET /posts/1/edit def edit @post = Post.find(params[:id]) end # POST /posts # POST /posts.xml def create @post = Post.new(params[:post]) respond_to do |format| if @post.save flash[:notice] = 'Post was successfully created.' format.html { redirect_to(@post) } format.xml { render :xml => @post, :status => :created, :location => @post } else format.html { render :action => "new" } format.xml { render :xml => @post.errors, :status => :unprocessable_entity } end end end # PUT /posts/1 # PUT /posts/1.xml def update @post = Post.find(params[:id]) respond_to do |format| if @post.update_attributes(params[:post]) flash[:notice] = 'Post was successfully updated.' format.html { redirect_to(@post) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @post.errors, :status => :unprocessable_entity } end end end # DELETE /posts/1 # DELETE /posts/1.xml def destroy @post = Post.find(params[:id]) @post.destroy respond_to do |format| format.html { redirect_to(posts_url) } format.xml { head :ok } end end end
Si quelqu'un pouvait m'expliquer ... merci d'avance
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 <table> <tr> <th>Nom</th> <th>Prenom</th> <th>Numero</th> <th>Adresse</th> <th>Cp</th> <th>Ville</th> <th>Tel</th> </tr> <% for post in @posts %> <tr> <td><%=h post.nom %></td> <td><%=h post.prenom %></td> <td><%=h post.numero %></td> <td><%=h post.adresse %></td> <td><%=h post.cp %></td> <td><%=h post.ville %></td> <td><%=h post.tel %></td> <!-- reference a notre id--> <td><%= link_to 'Consulter', post %></td> <td><%= link_to 'Modifier', edit_post_path(post) %></td> <td><%= link_to 'Supprimer', post, :confirm => 'Etes vous sur ?', :method => :delete %></td> </tr> <% end %> </table> <br /> <%= link_to 'Nouveau Message', new_post_path %>
Partager