0

I'm trying to setup a messaging system in my site using the Mailboxer gem in Rails 4. When my app gets to this code:

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

it returns the error: undefined method '[]' for nil:NilClass

enter image description here

I've tried to figure this out, but I'm not very experienced. I've been following this tutorial: http://jamestansley.com/2014/02/22/customizing-the-mailboxer-ruby-gem-2/

I tried removing the line of code returning the error just to see what would happen, after which I received the error wrong number of arguments (1 for 2..6).

w

Can anyone attempt to explain this code to me? Been having a really rough time implementing this feature.

view/conversations/_form:

<%= simple_form_for :conversation, url: :conversations do |f|  %>
<%= f.input :recipients %>
<%= f.input :subject %>
<%= f.input :body %>

<div class="form-actions">
  <%= f.button :submit, class: 'btn-primary' %>

  <%= submit_tag 'Cancel', type: :reset, class: 'btn btn-danger' %>
</div>

<% end %>

view/conversations/show:

<h1><%= @conversation.subject %> </h1>
<!--may have to work on this view. don't know if i did the haml conversion correctly-->
<h1> <%= conversation.subject %> </h1>
    <ul>
        <% content_tag_for(:li, conversation.receipts_for(current_user)) do |receipt| %>
            <%= message = receipt.message %>
            <h3><%= message.subject %> </h3>
            <p><%= message.body %> </p>
    </ul>
<% render 'messages/form', conversation: conversation %>
<% end %>

And here's my github repo:

https://github.com/portOdin/GoFavorIt-Heroku/blob/8cd19ff5b61eb805dc694a6586f50df608752be2/app/views/conversations/show.erb
domi91c
  • 1,962
  • 4
  • 23
  • 38
  • It looks like whatever "self" is referencing is nil. Make sure you're setting the class before attempting to call the class's methods. – MCBama Jun 09 '14 at 01:03
  • There's not really a problem with the `fetch_params` method--the issue is that the `reply` method is not receiving the `params` hash it expects. Can you post your `show` conversations controller method and your `_form.html.erb` (the reply form)? – Jacob Brown Jun 09 '14 at 14:20

0 Answers0