尝试使用 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 %>
运行此返回此错误:
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
@support 变量已创建并且不是 nil - 我可以从日志中看到它。这在 Rails 3.0 中也运行良好,但现在在迁移到 Rails 3.2 后,它不知何故坏了。
这是一类支持变量。这用于向管理员发送电子邮件反馈:
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
尝试了不同的东西,但仍然看不出这里有什么问题。导轨 3.2.1。