Topic: Behind the scaffolding
I'm a rails newbie and I'm trying to figure out how to create, update, delete, list and individually view models using simple forms. The problem is that most tutorials seem to do this using scaffolding.
I've put together something that seems to work but, in all honesty I don't understand it! I've attached the code for a view and the corresponding action in the controller.
Here's the view:
<%= form_tag :action => 'create_post' %>
<td><%= text_field ('post', 'title') %></td>
<td><%= text_field ('post', 'post_body') %></td>
<td><%= submit_tag 'Save' %><td>
Here's the code for the action. Where does (params[:post]) come from? I guess the view created a post object? How did we tell it to do that? I know we've associated the text fields with fields on the post model (e.g. "text_field ('post', 'post_body')", but where does the object come from?
class ForumController < ApplicationController
@post = Post.new(params[:post])
redirect_to :action => 'post_created', :id => @post
render :action => 'create_post'
@post = Post.find(params[:id])
The other thing is that I don't really understand the process by which the assignment of @post works in the view_post code. I mean, in the create_post method we've assigned the whole post to :id... shouldn't it be ":id => @post.id" ?
I know these things will be obvious to most people, but I'm having trouble finding answers to this stuff, and I don't like writing code that I don't understand )
I'd appreciate any help with this
Last edited by segfaultsoul (2006-11-19 10:01:53)