0

我正在使用mailboxer gem,我想制作对话(show.html.haml)JSON格式以及邮箱(index.html.haml)JSON格式。

我试着像这样把它放在一个普通的 response_to 块中

 respond_to do 
   format.json { render :json => @conversation }
 end

但它没有用。它说堆栈级别太深。有什么我想念的吗?

这些是控制器代码

   def mailbox
     @mailbox ||= current_user.mailbox
   end

   def conversation
      @conversation ||= mailbox.conversations.find(params[:id])

   end
4

1 回答 1

1

I ended up figuring out what the problem was, I needed to add a show and index into my conversations controller so that I could then render in json. For anyone else that may have this problem this was what I did and it worked fine.

   def index
     @mailbox ||= current_user.mailbox

     respond_to do |format|
       format.html
       format.json { render :json => @mailbox }
     end
   end    

   def show
     @conversation ||= mailbox.conversations.find(params[:id])

     respond_to do |format|
       format.html
       format.json { render :json => @conversation }
     end
   end

Hope this helps!

于 2013-03-16T13:23:28.813 回答