Hi Guys,

So basically I want a contact form to appear on all the service pages.
I've already created a contact form for the contact page which works
perfectly using this tutorial:
http://matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3/

Now I would like to implement this approach on the service pages, and it
works until I push the Submit button, when I get the following error:

Processing by ScontactController#create as HTML

Completed 500 Internal Server Error in 1ms

NoMethodError (undefined method `each' for nil:NilClass):
   app/models/servicemail.rb:13:in `initialize'
   app/controllers/scontact_controller.rb:9:in `new'
   app/controllers/scontact_controller.rb:9:in `create'

The parameters are ok.

Rails seems to complain about the each method in the model:
class Servicemail

   include ActiveModel::Validations
   include ActiveModel::Conversion
   extend ActiveModel::Naming

   attr_accessor :name, :email, :subject, :body, :szolg

   validates :name, :email, :subject, :body, :presence => true
   validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank =>
true

   def initialize(attributes = {})
     attributes.each do |name, value|
       send("#{name}=", value)
     end
   end

   def persisted?
     false
   end

end

This is the controller:
class ScontactController < ApplicationController

   def new
     @message = Servicemail.new
     @szolg = Service.find_by_permalink!(params[:id])
   end

   def create
     @message = Servicemail.new(params[:message])
     @szolg = Service.find_by_permalink(params[:id])

     if @message.valid?
       ServiceContact.new_message(@message).deliver
       redirect_to(szolg_path(@szolg), :notice => "Message sent
successfully!")
     else
       flash.now.alert = "Please fill out all the required fields!"
       render :new
     end
   end

end


Is it the name of the model/view/controller that bothers Rails or is it
something else?

Best Wishes,
Matt

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7b49e328-2ca1-4f10-bfd7-c46becc3f743%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Colin Law at Jun 23, 2013 at 4:24 pm

    On 23 June 2013 05:20, Máté Kaszás wrote:
    Hi Guys,

    So basically I want a contact form to appear on all the service pages.
    I've already created a contact form for the contact page which works
    perfectly using this tutorial:
    http://matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3/

    Now I would like to implement this approach on the service pages, and it
    works until I push the Submit button, when I get the following error:

    Processing by ScontactController#create as HTML

    Completed 500 Internal Server Error in 1ms

    NoMethodError (undefined method `each' for nil:NilClass):
    app/models/servicemail.rb:13:in `initialize'
    That means that at that line of code you are calling 'each' on
    something that is nil.
    app/controllers/scontact_controller.rb:9:in `new'
    app/controllers/scontact_controller.rb:9:in `create'

    The parameters are ok.

    Rails seems to complain about the each method in the model:
    class Servicemail

    include ActiveModel::Validations
    include ActiveModel::Conversion
    extend ActiveModel::Naming

    attr_accessor :name, :email, :subject, :body, :szolg

    validates :name, :email, :subject, :body, :presence => true
    validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank =>
    true

    def initialize(attributes = {})
    attributes.each do |name, value|
    Assuming that the above is line 13 then it means that attributes is nil.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsdfNpm3rgWboLsAfeugh5cmk71SntH0yhVhM1g%3DQ2E5g%40mail.gmail.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJun 23, '13 at 4:16p
activeJun 23, '13 at 4:24p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Colin Law: 1 post Máté Kaszás: 1 post

People

Translate

site design / logo © 2021 Grokbase