Rails新手在這裏。我正在嘗試這個郵箱寶石,並在我的網站上實施。我想創建一個收件箱系統,但不知何故它沒有向我顯示對話顯示頁面。它給我以下錯誤:Rails - NameError undefined局部變量或方法`對話'
NameError in Conversations#show Showing C:/Sites/myinbox/app/views/conversations/show.html.haml where line #6 raised:
undefined local variable or method `conversation'
我不會在哪裏出錯。我正在關注如何設置它的教程here,但我沒有收到要顯示的對話。
我真的很感激,如果你願意幫忙!
show.html.haml
.row
.spacer
.col-md-6
= link_to "Compose", new_conversation_path, class: "btn btn-success"
.col-md-6.text-right
- if conversation.is_trashed?(current_user) <!-- LINE 6 -->
= link_to 'Untrash', untrash_conversation_path(conversation), class: 'btn btn-info', method: :post
- else
= link_to 'Move to trash', trash_conversation_path(conversation), class: 'btn btn-danger', method: :post, |
data: {confirm: 'Are you sure?'} |
.row
.spacer
.col-md-4
.panel.panel-default
.panel-body
= render 'mailbox/folders'
.col-md-8
.panel.panel-default
.panel-body
= render partial: 'messages'
.panel-footer
/Reply Form
= form_for :message, url: reply_conversation_path(conversation) do |f|
.form-group
= f.text_area :body, placeholder: "Reply Message", rows: 4, class: "form-control"
= f.submit "Reply", class: 'btn btn-danger pull-right'
conversations_controller.rb
class ConversationsController < ApplicationController
before_action :authenticate_user!
def new
end
def create
recipients = User.where(id: conversation_params[:recipients])
conversation = current_user.send_message(recipients, conversation_params[:body], conversation_params[:subject]).conversation
flash[:notice] = "Your message was successfully sent!"
redirect_to conversation_path(conversation)
end
def show
@receipts = conversation.receipts_for(current_user).order("created_at ASC")
# mark conversation as read
conversation.mark_as_read(current_user)
end
def reply
current_user.reply_to_conversation(conversation, message_params[:body])
flash[:notice] = "Your reply message was successfully sent!"
redirect_to conversation_path(conversation)
end
def trash
conversation.move_to_trash(current_user)
redirect_to mailbox_inbox_path
end
def untrash
conversation.untrash(current_user)
redirect_to mailbox_inbox_path
end
private
def conversation_params
params.require(:conversation).permit(:subject, :body,recipients:[])
end
def message_params
params.require(:message).permit(:body, :subject)
end
end
您需要將'conversation'聲明爲'@ conversation'。因爲視圖只能訪問實例變量。 –
本教程的下一步(在此控制器中創建'對話'輔助方法的那一步)應該有所幫助。 –