Any reason for this? What if the first forum gets deleted?
forum = Forum.find_by_id(params[:forum_subject][:forum_id])
Instead of using find_by_id just use find, that is unless you want to
return
nil rather than an ActiveRecord::RecordNotFound exception (which should
never occur unless the user does something wrong)
I dont really know how to add a new post to this at the same time I
could assume to do that this way:
create new forum subject
get the last insert_id of the forum_subject - add new post to the
subject
The thing is I cant find the way to get the last insert_id (for finding
the subject)
What’s the model for your posts? Post? Do you have a controller
specific, a default one, for that controller?
Adam, if you’re still looking for some help I’ll be glad to help you
out,
add me as [email protected] on MSN if you have it, or on
googletalk.
Alternatively you can shoot me an email.
I guess what I’m doing right now is pretty simple but after a days
work it can be hard to figure it out.
I did a pretty simple form for topic and the post, like in a usual
forum the user can create a topic and add the first post.
Here’s the short version of the form.
You shouldn’t need to pass in user_id and forum_id as hidden fields, as
user_id should be stored as a session variable (session[:user]) and
forum_id
should come from the URL.
Adam, if you’re still looking for some help I’ll be glad to help you
out,
add me as [email protected] on MSN if you have it, or on
googletalk.
Alternatively you can shoot me an email.
–
Ryan B.
Feel free to add me to MSN and/or GTalk as this email.
<%= render :partial=>‘topics/form’,:locals=>{:f=>f} %>
def create
render :action => :new
I’m working on them thought
Feel free to add me to MSN and/or GTalk as this email.
–
Ryan B.
Feel free to add me to MSN and/or GTalk as this email.
or #this code I would move into a private method called find_forum @forum = Forum.find(params[:forum_id]) @topic = @forum.topics.build
If you’re doing just Topic.new I think it’ll just redirect to /topics,
but
if you do it either of the ways I specified it should go to
/forums/2/topics
On Thu, Mar 13, 2008 at 6:51 PM, Adam [email protected] wrote:
Putting the forum aside I was trying to make a faq, type thing for my
project also using rest
so i went to the config/routes.rb typed
map.resources :subject, :has_many=>:faqs
map.resources :faqs
And when i’m trying to add a new faq to existing subject via
subjects/2/faqs/new
And when i’m sending the form it’s redirected to /faqs with the same
error message
I’ll give the full code (after the modifications) cause I just don’t
know what to do anymore I’m getting redirected to /topics with the
message Couldn't find Forum without an ID
the controller:
class TopicsController < ApplicationController
before_filter :user_logged_in?
layout :switch_layout
def index @topics = @forum.topics
end
def new @forum = Forum.find params[:forum_id] @topic =
Topic.new :forum_id=>params[:forum_id], :user_id=>session[:user_id] @post = Post.new
end
flash[:notice] = 'Created new topic' if @topic.save!
redirect_to forums_path
rescue ActiveRecord::RecordInvalid
render :action => :new
end
def edit @topic = Topic.find params[:id]
end
def update @topic = Topic.find params[:id]
if @topic.update_attributes params[:topic]
flash[:notice] = “Changed #{@topic.name}”
redirect_to forum_path(@topic.forum_id)
end
rescue ActiveRecord::RecordInvalid
render :action => :edit
end
def destroy
topic =Topic.find params[:id]
if topic.destroy
flash[:notice] = “topic: #{topic.name} was deleted”
end
redirect_to forum_path(topic.forum_id)
end
def show @posts = Topic.find(params[:id]).posts
end
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.