On Apr 30, 2011, at 11:40 AM, amrit pal pathak wrote:
This time i read scaffold tutorial very carefully and finally try to
generate a form without using the scaffold(just used a controller and
view ).what i have done till now ,is as follow.Using rails 3.0.7.
"rails generate controller posts
index"
1) post_controller.rb
class PostsController < ApplicationController
def index
@post=Post.new
end
def create
@post = Post.new(params[:post])
respond_to do |format|
end
end
end
2)index.html.erb
<h1>Posts#index</h1>
<p>Find me in app/views/posts/index.html.erb</p>
<%= link_to 'New Post', new_post_path%>
<%= form_for(@post) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
i didnt create any model because i just
want to create a simple form first.so when i brower to "localhost:
3000/
posts/index", it says
"uninitialized constant PostsController::Post
Please somebody help to resolve it
Thanks
You must have a model if you're going to call Post.new. That's where
that 'new' method happens. The model tells the controller what fields
it should initialize, which tells the view that the default values are
whatever they are, etc. It's MVC, not VC!
Walter
--
You received this message because you are subscribed to the Google
Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-
t...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com
.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
.
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.