我正在實施郵箱gem到我的應用程序,並認爲這應該工作,但得到上述錯誤,我認爲它與|| =操作做正式參數不能是一個實例變量def trash_folder @trash || = current_user.mailbox.trash.all結束^
我得到這個
conversations_controller.rb:16: formal argument cannot be an instance variable def
trash_folder @trash ||= current_user.mailbox.trash.all end^
/home/action/booklist/app/controllers/conversations_controller.rb:16: syntax error,
unexpected tOP_ASGN, expecting ';' or '\n' def trash_folder @trash ||=
current_user.mailbox.trash.all end^
/home/action/booklist/app/controllers/conversations_controller.rb:18: syntax error, unexpected '.', expecting ';' or '\n' def trash conversation.move_to_trash(current_user)
...^/home/action/booklist/app/controllers/conversations_controller.rb:18: syntax
error, unexpected tIDENTIFIER, expecting end-of-input ...rash(current_user) redirect_to
:conversations end ...^
Conversations_controller:
class ConversationsController < ApplicationController
helper_method :mailbox, :conversation
def index
@conversations ||= current_user.mailbox.inbox.all
end
def reply
current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
redirect_to conversation
end
def trash_folder @trash ||= current_user.mailbox.trash.all end
def trash conversation.move_to_trash(current_user) redirect_to :conversations end
def untrash conversation.untrash(current_user) redirect_to :back end
def empty_trash current_user.mailbox.trash.each do |conversation| conversation.receipts_for(current_user).update_all(:deleted => true)
end
redirect_to :conversations
end
private
def mailbox
@mailbox ||= current_user.mailbox
end
def conversation
@conversation ||= mailbox.conversations.find(params[:id])
end
def conversation_params(*keys)
fetch_params(:conversation, *keys)
end
def message_params(*keys)
fetch_params(:message, *keys)
end
def fetch_params(key, *subkeys)
params[key].instance_eval do
case subkeys.size
when 0 then self
when 1 then self[subkeys.first]
else subkeys.map{|k| self[k] }
end
end
end
會話視圖索引:
<% @conversations.each do |conversation| %>
<% if participant != current_user %>
<%= participant.name, participant %>
<% end %>
<%= link_to conversation.subject, conversation %>
<%= conversation.updated_at.strftime("%a, %m/%e/%Y %I:%M %p") %>
<%= link_to "Move to Trash", {:controller => "conversations", :action => "trash", :id => conversation.id}, :title=> "Move to Trash", :method=>'post' %>
<% end %>
,並鏈接到收件箱中current_user_session路徑
<%= link_to "inbox", conversations_path %>
我還有其他的意見,但我認爲這個問題是在對話控制器。我不確定這些錯誤發生了什麼,它應該可以工作
這裏的格式化是一場完全災難。有什麼方法可以修復它並使其更具可讀性? – tadman