0

I'm trying to embedded mail_form into my home page.

The 'contacts#new' is rendered on 'static_pages#home' so I instantiate @contact in StaticPagesController's home action to avoid the "First argument in form cannot contain nil or be empty" error.

But I now I get wrong number of arguments (0 for 1..2) errors instead.

I see this behaviour since I updated my ruby to 2.2.2.

Do you think this error is caused by new specification on Ruby, or it is just my simple code error?

static_pages_controller

class StaticPagesController < ApplicationController

def home
  @contact = Contact.new
end

end

views/static_pages/home.html.erb

<section id="contact">
  <%= render template: 'contacts/new' %>
</section>

contacts_controller

class ContactsController < ApplicationController

def new
  @contact = Contact.new
end

def create
  @contact = Contact.new(contact_params)
  @contact.request = request

  if @contact.deliver
    flash.now[:notice] = "Thank you for your message. We will contact you soon!"
  else
    flash.now[:error] = "Cannot send message."
    render 'new'
  end
end

private

def contact_params
  params.require(:contact).permit(:name, :email, :message)
end

end

views/contacts/new.html.erb

<%= form_for(@contact) do |f| %>
...
<% end %>

Logs

Processing by StaticPagesController#home as HTML
Rendered contacts/new.html.erb (23.5ms)
Rendered static_pages/home.html.erb within layouts/application (238.2ms)
Completed 500 Internal Server Error in 278ms

ArgumentError (wrong number of arguments (0 for 1..2)):
app/views/contacts/new.html.erb:28:in `block in_app_views_contacts_new_html_erb___4238619170782302276_70113984753480'
d_dnara
  • 49
  • 1
  • 5
  • To clarify: the error happens in `@contact = Contact.new` ? – Marcus Ilgner Apr 20 '15 at 18:07
  • @ma_il :YES, it seems like that. I also try on 'contacts/new' page, but it gives me the same error. It must be something wrong with ruby version or the Gem set that I specified. – d_dnara Apr 20 '15 at 18:35

1 Answers1

0

I update my version of 'byebug' to '4.0.1' and 'Web-console' to '2.1.2', then it shows where was the error. It was actually really stupid ...

Error:

<%= form_for(@contact) do |f| %>

<%= t.email_field ... %>
...
<% end %>

Correct:

<%= form_for(@contact) do |f| %>

<%= f.email_field ... %>
...
<% end %>
d_dnara
  • 49
  • 1
  • 5