0

I didn't figure out the mechanics of the routing yet..

I have a User, Msg and comment model.

A User creates a Msg and inside the msg i'd like to put simple text box for comments. similar to twitter.

However, When the the form is submitted (using the form below) instead of returning to localhost/msgs/:id it returns to localhost/comments.

I have no view for /comments and I don't want to have. I want all comments to be displayed in msg/:id page.

comments controller:

class CommentsController < ApplicationController

before_filter :authenticate


def create


msgid = flash[:msg]
@current_msg = Msg.find(discid)
@comm = @current_msg.comments.build(params[:comment])
@comm.user_id = current_user.id
@comm.msg_id = msgid
puts discid
if @comm.save
    flash[:success] = "Comment posted"
    redirect_to msg_path(discid)

else
    flash[:error] = "Comment was not posted."
    redirect_to msg_path(discid)


end

end

route.rb

match '/comments' , :to => 'msgs#show'

  resources :users
  resources :msgs

since the comments are displayed in the show view of the msgs here is the show action in the msgs controller

def show

    @msg= Msg.find(params[:id])
    @title = @msg.title
    @comment = Comment.new
    @comments = @msg.comments.all
    flash[:msg] = @msg.id

end

The error I get is

ActiveRecord::RecordNotFound in MsgsController#show

Couldn't find Msgwithout an ID

and it points to line 46 which at the moment is @msg = Msg.find(params[:id])

If I remove the route line and put a regular resources :comments I get a missing template for comments/create..

Help is appreciated.

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • Issue solved.. I add a :id => discid in the redirec_to.. Also used http://stackoverflow.com/questions/6495046/template-is-missing to understand the issue – Nick Ginanto Dec 02 '11 at 15:37
  • 1
    Please put that as an answer and mark it as accepted so other people know this question is solved – iwasrobbed Dec 02 '11 at 15:54

1 Answers1

0

Issue solved.. I add a :id => discid in the redirecא_to..

Also used Template is missing to understand the issue

Community
  • 1
  • 1
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244