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.