<%= f.input :schedule, as: :datetime, input_html: {id: 'schedule'} %>
添加日期时间选择器后,我遇到了一个奇怪的错误。我想知道,问题可能是什么?
NoMethodError in Messages#new
和
undefined method ``schedule' for #<Message:0x000000066fa1e8>
我的创建控制器是
def create
@lists = current_user.lists.all
@message = Message.new(params[:message])
lists = params[:message][:lists]
schedule = params[:message][:schedule]
if @message.save
if schedule == [""]
MessageWorker.perform_async(@message.id, lists, current_user.id)
else
Schedule.create(execution_time: schedule, lists: lists, message_id: @message_id, user_id: current_user.id)
end
else
render action: "new"
flash[:notice] = "Messages Not Sent"
end
end
观点是;
<%= simple_form_for(@message, :html => {:multipart => true}) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :from, placeholder: "Max 11 characters" , input_html: {id: 'sms_from'} %>
<%= f.input :to, :input_html => {:value => params[:to], :class => "to"}, placeholder: "Separate Numbers with Comma", hint: "Include atleast one number in this section. Separate the numbers with commas." %>
<div id="add_lists"> <span class="button"> Add List </span></div>
<div id="all_lists"> <%= f.collection_check_boxes :lists, @lists, :id, :name, as: :select %></div>
<%= f.input :message, :as => :text, :input_html => {:cols => 60, :rows => 7, id: "compose_message", placeholder: 'Type your message here!'} %>
<div>
<p>
<span id="char_count">160 characters left</span>
<span id="number_of_messages">1 message(s)</span>
</p>
</div>
<%= f.input :schedule, as: :datetime, input_html: {id: 'schedule'} %>
<%= f.input :user_id, :as => :hidden, :input_html => {:value => @current_user.id} %>
<%= f.input :status, :as => :hidden, :input_html => {:value => "Queued"} %>
<%= f.button :submit, "Send Message" %>
<% end %>
模型顶部看起来像这样;
class Message < ActiveRecord::Base
attr_accessible :message, :phone, :status, :to, :from, :user_id, :schedule
validates :message, :presence => true
validates :from, :presence => true
validates :to, :presence => true
validates :status, :presence => true
validates_length_of :message, :maximum => 1600, :allow_blank => true
validates_length_of :from, :maximum => 11, :allow_blank => false
belongs_to :user
在我添加之前,一切都运行良好;
<%= f.input :schedule, as: :datetime, input_html: {id: 'schedule'} %>