• Ruby on Rails 3 - Need help with syntax on accessing a member of an object properly
    0 replies, posted
[IMG]http://i.imgur.com/MckS8.png[/IMG] 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. [CODE]undefined method `contact_email' for nil:NilClass [/CODE] I denoted the lines I think are wrong with "<------- THIS LINE" emailinterests_controller.rb [CODE] def create @emailinterest = Emailinterest.new(params[:emailinterest]) respond_to do |format| if @emailinterest.save [b]Notifier.emailinterest_notification(self, @submission).deliver[/b] <------- THIS LINE format.html { redirect_to(@emailinterest, :notice => 'Email was successfully sent!') } format.xml { render :xml => @emailinterest, :status => :created, :location => @emailinterest } else format.html { render :action => "new" } format.xml { render :xml => @emailinterest.errors, :status => :unprocessable_entity } end end end[/CODE] "self" refers to the emailinterest object that's being emailed. @submission should refer to the current object that emailinterest object is interacting with. [B]notifier.rb[/B] [CODE][b]def emailinterest_notification(emailinterest, submission)[/b] <------- THIS LINE @emailinterest = emailinterest @submission = submission [b]mail :to => submission.contact_email,[/b] <------- THIS LINE :from => emailinterest.sender_email, :subject => 'actuirl.com - RE:' + submission.title end[/CODE]
Sorry, you need to Log In to post a reply to this thread.