11155
(-- --)
March 18, 2011, 11:51pm
1
I'm studing a forum and when I create a Topic I have a _form.html.erb
relative a file inside follow directory
#app /views
new.html.erb
_form.html.erb
....
....
the snippet controller to create a new topic is the follow
#app /controllers/topics_controller.rb
def create
@topic = Topic.new(params[:topic])
if @topic.save
@topic = Topic.new(:name => params[:topic][:name], :forum_id =>
params[:topic][:forum_id])
if @post.save
flash[:notice] = "Successfully created topic."
redirect_to "/forums/#{@topic.forum_id }"
else
render :action => 'new'
end
else
render :action => 'new'
end
end
11155
(-- --)
March 19, 2011, 12:29am
2
No need create only 2 simple line in the follow file
#app /controllers/topics_controllers
def new
@topic = Topic.new
@post = Post.new
end
def create
def create
@topic = Topic.new(params[:topic])
if @topic.save
@topic = Topic.new(:name => params[:topic][:name], :forum_id =>
params[:topic][:forum_id])
@post = Post.new(:content => params[:post][:content], :topic_id =>
Topic.first.id)
if @post.save
flash[:notice] = "Successfully created topic."
redirect_to "/forums/#{@topic.forum_id }"
else
render :action => 'new'
end
else
render :action => 'new'
end
end