I cannot get my form to submit for my simple blog site (based on the
“How to Build a Blog Engine in 15 Minutes” presentation)
Any ideas?
Thanks,
Tom
Here is my code:
#Post controller
class PostsController < ApplicationController
def index
list
render :action => ‘list’
end
GETs should be safe (see
URIs, Addressability, and the use of HTTP GET and POST)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
@post_pages, @posts = paginate :posts, :per_page => 10
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def create
@post = Post.new(params[:post])
if @post.save
flash[:notice] = ‘Post was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
flash[:notice] = ‘Post was successfully updated.’
redirect_to :action => ‘show’, :id => @post
else
render :action => ‘edit’
end
end
def destroy
Post.find(params[:id]).destroy
redirect_to :action => ‘list’
end
#def to control submitting ideatrain
def ideatrain
Post.find(params[:id]).ideatrains.create(params[:ideatrain])
flash[:notice] = “Added your comment.”
redirect_to :action => “show”, :id => params[:id]
end
end
#show.rhtml
<%= render :partial=>“form”, :object => @ideatrain %>
<%= link_to ‘Edit’, :action => ‘edit’, :id => @post %> |
<%= link_to ‘Back’, :action => ‘list’ %>
Threads
<% for ideatrain in @post.ideatrains %> <%=ideatrain.thread_subject %><%= ideatrain.thread_body %>
<% end %>
<% form_tag :action => “ideatrain”, :id => @post %>
<%= text_area “ideatrain”, “body” %>
<%= submit_tag “Ideatrain!” %>
#Partial form
<%= error_messages_for ‘post’ %>
Subject
<%= text_field 'post', 'subject' %>
Poster
<%= text_field 'post', 'poster' %>
Date
<%= datetime_select 'post', 'date' %>
Time range
<%= datetime_select 'post', 'time_range' %>
Stage
<%= text_field 'post', 'stage' %>
Votes
<%= text_field 'post', 'votes' %>