Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 - Syntax error - Accessing member of object
    text
    copied!<p><img src="https://i.stack.imgur.com/vSWpq.png" alt="enter image description here"></p> <p>My app is something like Kijiji's email reply system. For each post, user can choose to reply to the post. I get this error when I submit.</p> <pre><code>Undefined method `contact_email' for nil:NilClass </code></pre> <p>I denoted the line that is causing the error below with **</p> <p>emailinterests_controller.rb</p> <pre><code>def create @emailinterest = Emailinterest.new(params[:emailinterest]) respond_to do |format| if @emailinterest.save **Notifier.emailinterest_notification(self, @submission).deliver** format.html { redirect_to(@emailinterest, :notice =&gt; 'Email was successfully sent!') } format.xml { render :xml =&gt; @emailinterest, :status =&gt; :created, :location =&gt; @emailinterest } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @emailinterest.errors, :status =&gt; :unprocessable_entity } end end end </code></pre> <p>"self" refers to the emailinterest object that's being emailed. @submission should refer to the current object that emailinterest object is interacting with.</p> <p>notifier.rb</p> <pre><code>**def emailinterest_notification(emailinterest, submission)** @emailinterest = emailinterest @submission = submission **mail :to =&gt; submission.contact_email,** :from =&gt; emailinterest.sender_email, :subject =&gt; 'actuirl.com - RE:' + submission.title end </code></pre> <hr> <h1>FIX</h1> <p><strong>C:\Rails\actuirl5\app\controllers\emailinterests_controller.rb</strong></p> <pre><code>def create @emailinterest = Emailinterest.new(params[:emailinterest]) @submission = Submission.find(params[:submission_id]) respond_to do |format| if @emailinterest.save Notifier.emailinterest_notification(@emailinterest, @submission).deliver format.html { redirect_to(@emailinterest, :notice =&gt; 'Email was successfully sent!') } format.xml { render :xml =&gt; @emailinterest, :status =&gt; :created, :location =&gt; @emailinterest } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @emailinterest.errors, :status =&gt; :unprocessable_entity } end end end </code></pre> <p><strong>C:\Rails\actuirl5\app\views\submissions_form_new_emailinterest.html.erb</strong></p> <pre><code>&lt;%= form_for(emailinterest) do |f| %&gt; &lt;%= hidden_field_tag :submission_id, value = @submission.id %&gt; &lt;div class="field"&gt; &lt;%= f.label :sender_email %&gt;&lt;br /&gt; &lt;%= f.text_field :sender_email %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :sender_email_content %&gt;&lt;br /&gt; &lt;%= f.text_area :sender_email_content %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p><strong>C:\Rails\actuirl5\app\views\submissions\show.html.erb</strong></p> <pre><code>&lt;%= render :partial=&gt;"form_new_emailinterest", :locals=&gt;{:emailinterest=&gt;Emailinterest.new} %&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload