をのform_for使用しようとすると、私はこのエラーを取得していリターンのform_forの使用:未定義のメソッドが `nilには参加:</p> <p>_feedback_form.html.erb:NilClass
がこのエラーを返し実行<%= 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
は異なるものを試しましたが、それでもここに間違っているものを見ることができません。 Rails 3.2.1。
うわー、ありがとう、私はちょうどそのto_keyメソッドをコメントし、それは働いた!おそらく、古いRailsのいくつかの例からのものでした。 –
フォームオブジェクトで遊んでいたときにこの問題に遭遇しました。私の場合、フォームオブジェクトにto_keyメソッドを追加することで問題は解決しました。ありがとう! –