Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Contact Forms - Rails 3
    primarykey
    data
    text
    <p>I am relative newbie to all this, so sorry if this sounds mad!</p> <p>I have used this tutorial: <a href="http://www.railsmine.net/2010/03/rails-3-action-mailer-example.html" rel="nofollow">http://www.railsmine.net/2010/03/rails-3-action-mailer-example.html</a> </p> <p>And I have a new contact form working great.</p> <p>The controller is at app/controllers/support_controller.rb</p> <pre><code>class SupportsController &lt; ApplicationController def new # id is required to deal with form @support = Support.new(:id =&gt; 1) end def create @support = Support.new(params[:support]) if @support.save redirect_to('/', :notice =&gt; "Support was successfully sent.") else flash[:alert] = "You must fill all fields." render 'new' end end end </code></pre> <p>And the model at /app/models/support.rb</p> <pre><code>class Support include ActiveModel::Validations validates_presence_of :email, :sender_name, :support_type, :content # to deal with form, you must have an id attribute attr_accessor :id, :email, :sender_name, :support_type, :content def initialize(attributes = {}) attributes.each do |key, value| self.send("#{key}=", value) end @attributes = attributes end def read_attribute_for_validation(key) @attributes[key] end def to_key end def save if self.valid? Notifier.support_notification(self).deliver! return true end return false end end </code></pre> <p>The views however only work in views/supports/new.html.rb (rendered - views/supports/_form.html.erb)</p> <p>So I can call the Model / Controller from localhost:3000/support/new but if I try and render the same form in another view from the root directory e.g. app/view/contact.html.erb I get: </p> <pre><code>undefined method `model_name' for NilClass:Class </code></pre> <p>I think this is because it is calling the support model away from the supports directory. </p> <p>Do I have to create an instance on @support so it can be called? If so what is the best way of doing that? I think I am nearly there. I just want the contact form on multiple pages not just in suppport/new</p> <p>Thanks</p> <p>Charlie</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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