rendered paste body@@The ERROR:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.ip
-------------------------------------------------------------------
@@The FORM:
<div id="contactUs">
<h2>Contact Us</h2>
<strong> <%= flash[:notice] %></strong>
<% form_tag :controller=>"contacts", :action=>"create" do %>
<table>
<tr>
<th>Name: </th>
<td><%= text_field 'contact', 'name', "size"=>20 %></td>
</tr>
<tr>
<th>Email: </th>
<td><%= text_field 'contact', 'email', "size"=>20 %></td>
</tr>
<tr>
<th>URL: </th>
<td><%= text_field 'contact', 'website', "size"=>20 %></td>
</tr>
<tr>
<th>Subject: </th>
<td><%= text_field 'contact', 'subject', "size"=>20 %></td>
</tr>
<tr>
<td></td>
<td><%= text_area 'contact', 'data' %></td>
</tr>
<tr>
<td></td>
<td><%= submit_tag "Submit" %></td>
</tr>
</table>
<% end %>
</div>
-------------------------------------------------------------------
@@controllers/ContactsController.rhtml
def create
@contact = Contact.new(params[:contact])
@contact.ip = @request.env['REMOTE_ADDR']
@contact.update_attributes(params[:contact])
if @contact.save
flash[:notice] = 'Your message was successfully sent.'
#Send an email
Notifier.deliver_contact_new(@contact)
redirect_to :controller=>'information', :action => 'contactUs'
else
render :action => 'new'
end
end
models/notifier.rb
class Notifier < ActionMailer::Base
def contact_new(contact)
subject = "You have received a new message"
recipients = 'jonathan@greatjobsofchina.com'
from = 'mail-noreply@greatjobsofchina.com'
body :info => @contact
end
end
-------------------------------------------------------------------
notifier/contact_new.rhtml
From:
Subject:
Date:
URL:
IP: <%= @info.ip %>
---------------------------------------------------------------------