Using form_for returns: undefined the `join 'method for nil: NilClass

I get this error when trying to use form_for:

_feedback_form.html.erb:

<%= form_for @support, :html => { :method => :post } do |f| %>
    <%= f.text_area :content, :class => "quick_feedback_form", :input_html => { :maxlength => 450 } %>
    <%= f.hidden_field :email, :value => current_user.email %>
    <div><%= f.submit "Send!", :disable_with => "Sending...", :class => "button white" %></div>
<% end %>

Running this function returns this error:

NoMethodError in Pages#guardian

Showing /home/alex/myapp/app/views/supports/_feedback_form.html.erb where line #1 raised:

undefined method `join' for nil:NilClass

The @support variable is created and is not nil - I see it from the log. This also works well in Rails 3.0, and now, after upgrading to Rails 3.2, it has somehow broken.

Here is the support class. This is used to send email to the administrator:

class Support < ActiveRecord::Base
include ActiveModel::Validations

  validates_presence_of :content 
  # to deal with form, you must have an id attribute
  attr_accessor :id, :email, :sender_name, :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?
      Feedback.support_notification(self).deliver
      return true
    end
    return false
  end
end

I tried different things, but still can not understand what is wrong here. Rails 3.2.1.

+3
source share
1 answer

, to_key. , ? ActiveRecord::Base, . , .

to_key - , , persisted (, ActiveRecord), . :

def to_key
  [self.id]
end

ActiveModel::Validations? ActiveRecord::Base.

+2

All Articles