Weired render action question! help! In a topic controller def edit @topic = Topic.find(params[:id]) end def update @topic = Topic.find(params[:id]) @topic.subject = params[:topic][:subject] @topic.body = params[:topic][:body] @topic.modificationDate = Time.now if @topic.update_attributes(params[:topic]) flash[:notice] = 'Topic was successfully updated.' redirect_to :action => 'show', :id => @topic.root_id else flash[:notice] = 'Failed to update the Topic.' render :action => 'edit' end end
edit.rhtml forum action --> update, if user input error, such as subject is null,then will render back edit.rhtml, and display the error message! it works! def newTopic @topic = Topic.new end def createTopic @topic = Topic.new(params['topic']) @topic.creationDate = Time.now @topic.modificationDate = Time.now if @topic.save flash[:notice] = 'Topic was successfully created.' redirect_to :action => 'index' else flash[:notice] = 'Failed to create a Topic' render :action => 'newTopic' end end if you want to post a new root topic, if subject is null, then render back to newTopic.rhtml, display error message! but..................................... def reply @parent = Topic.find(params[:id]) end def replyTopic parent = Topic.find(params[:parentID]) @topic = Topic.new(params['topic']) if parent.root? root_id = params[:parentID] else root_id = parent.root_id end @topic.root_id = root_id @topic.creationDate = Time.now @topic.modificationDate = Time.now if @topic.save flash[:notice] = 'Topic was successfully created.' parent.add_child(@topic) redirect_to :action => 'show', :id => root_id else flash[:notice] = 'Oops, there was a problem!' # redirect_to :action => 'new', :id => params[:parentID] render :action => 'reply' end end if you reply a topic, reply.rhtml will display parent topic information, then forum action to replyTopic, if user input error, it could'nt render back to reply.rhtml, display @parent nil object error!why? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Deploying Rails" group. To post to this group, send email to rubyonrails-deployment@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment?hl=en -~----------~----~----~----~------~----~------~--~---