0
我沒弄明白路由的機制尚未..錯誤的路由,軌道
我有一個用戶,消息和評論模型。
用戶創建一個味精和味精裏面我想提出簡單的文本框徵求意見。類似於twitter。
然而,當提交表單(使用下面的表格),而不是返回到本地主機/封郵件/:ID返回到localhost /評論。
我有/無意見和看法,我不希望有。我希望所有評論都能顯示在msg /:id頁面中。
評論控制器:
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
,因爲註釋顯示在這裏封郵件的顯示視圖在封郵件控制器的show動作
def show
@msg= Msg.find(params[:id])
@title = @msg.title
@comment = Comment.new
@comments = @msg.comments.all
flash[:msg] = @msg.id
end
我得到的錯誤是
ActiveRecord::RecordNotFound in MsgsController#show
Couldn't find Msgwithout an ID
並指向46行這在目前是@msg = Msg.find(PARAMS [:編號])
如果我刪除路徑線,把一個普通resources :comments
我得到一個丟失的模板評論/創建..
幫助表示讚賞。
問題解決了。我添加:ID =>盤標識符在redirec_to ..也使用http://stackoverflow.com/questions/6495046/template-is-missing瞭解問題 –
請把那作爲一個答案,標記爲接受,這樣其他人知道這個問題已經解決 – iwasrobbed