【发布时间】:2016-02-04 19:45:07
【问题描述】:
Rails 新手在这里。我正在尝试这个 Mailboxer gem 并在我的网站上实施。我想创建一个收件箱系统,但不知何故它没有向我显示对话显示页面。它给了我以下错误:
对话中的名称错误#show C:/Sites/myinbox/app/views/conversations/show.html.haml 在哪里 第 6 行提出:
未定义的局部变量或方法`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。因为,视图只能访问实例变量。 -
本教程的下一步(在此控制器中创建
conversation辅助方法)应该会有所帮助。
标签: ruby-on-rails ruby