Hi max
This is the code:
-- controllers/contact_controller.rb --
class ContactController < ApplicationController
layout "main"
def index
p params
if request.post?
@contact = Contact.new(params[:contact])
# Contact::deliver_signup_thanks(@contact)
render :text => @contact.name
end
end
end
-- views/contact/index.rhtml ---
<% @page_title = "contact" %>
<% @page_class = "contact" %>
<div id="ContentPrimary">
<h1><span>contact us</span></h1>
<div id="form">
<% form_for :contact do |form| %>
<h2>lorem ipsum dolor sit amet</h2
<h3>Donec fringilla. Nam odio ipsum, pretium tincidunt, eges tas ut,
hendrerit in, nisl. Suspendisse sagittis sceler isque ipsum</h3>
<%= error_messages_for 'contact' %>
<div class="row input">
<label for="contact_name">Your name:</label>
<%= form.text_field :name %></div>
<div class="row input">
<label for="contact_telephone_number">Your telephone number:</label>
<%= form.text_field :telephone_number %></div>
<div class="row input">
<label for="contact_email">Your email address:</label>
<%= form.text_field :email %></div>
<div class="row select">
<label for="contact_area_of_interest">Area of interest:</label>
<%= select("contact", "area_of_interest", Portfolio.find_all.collect
{|p| [ p.name, p.name ] } ) %></div>
<%= submit_tag "Send" %>
<% end %>
</div>
<div id="address">
<h3>adrian bodie</h3>
<p>Stanley Wharf Mill<br />Kirkebrok Rd<br />Deane<br />Bolton<br
/>BL3 3JE</p>
<div class="telephone">
<h4>telephone</h4>
<p>01294 665 200</p>
</div>
<div class="fax">
<h4>fax</h4>
<p>01294 665 200</p>
</div>
<div class="email">
<h4>email</h4>
<p>info@adrianbodie.com</p>
</div>
</div>
<div class="cleaner"></div>
</div>
-- models/contact.rb
class Contact < ActionMailer::Base
def signup_thanks( contact )
@body["contact"] = contact
# Email header info MUST be added here
@recipients = contact.email
# Email body substitutions go here
end
end
-- ERROR I GET --
NoMethodError in ContactController#index
You have a nil object when you didn't expect it!
The error occured while evaluating nil.name
RAILS_ROOT: /Users/jono/Sites/adrianbodie/public/../config/..
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/controllers/contact_controller.rb:9:in `index'
Request
Parameters: {"commit"=>"Send", "contact"=>{"name"=>"cds",
"area_of_interest"=>"General", "telephone_number"=>"xcacsc",
"email"=>""}}
Show session dump
Response
Headers: {"cookie"=>, "Cache-Control"=>"no-cache"}