Michael Peralta
Michael Peralta

Reputation: 293

Mailboxer JSON Format

I am using the mailboxer gem and I wanted to go about making the conversation (show.html.haml) JSON format and also the mailbox (index.html.haml) JSON format.

I tried putting it a normal respond_to block like this

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

but it didn't work. It says the stack level is too deep. Is there something I'm missing?

These are the controller code

   def mailbox
     @mailbox ||= current_user.mailbox
   end

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

   end

Upvotes: 0

Views: 155

Answers (1)

Michael Peralta
Michael Peralta

Reputation: 293

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!

Upvotes: 1

Related Questions