0
私はこの質問をearlierに今日求め、コンソールからは期待通りに動作します。しかし、フォームを組み込んで(たとえばajax、スタイル)、フォームに保存してもモデルに保存されていないようです。モデルはコンソールに保存されていますが、ウェブからは表示されません
私の修正を行うためのアイデアはありますか?
歓声 -
申し込みモデル
class Signup < ActiveRecord::Base
attr_accessible :email_address, :send_once, :send_any_time
# email_regex = stub it out later
validates :email_address, presence: true,
#format: {with: email_regex},
uniqueness: {message: 'there can only be one you.'}
end
をPagesController
class PagesController < ApplicationController
def index
@signup = Signup.new
end
def create
@signup = Signup.new(params[:signup])
if @signup.send_once == "1" or @signup.send_any_time == "1"
respond_to do |format|
if @signup.save
format.js
else
format.html {render action: :index}
end
end
else
#if they don't sign, do something!
end
end
end
__form.html.erb_
<%= form_for(@signup, method:post, as: :signup, url: pages_path, html: {id: "button"}, remote: true) do |f| %>
<% if @signup.errors.any? %>
<div id="error_explanation">
<p><%= pluralize(@signup.errors.count, "error") %> prohibited this post from being saved:</p>
<ul>
<% @signup.errors.full_messages.each do |user| %>
<li><%= user %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :email_address %><br />
<%= f.email_field :email_address %>
<%= f.label :send_once %><br />
<%= f.check_box :send_once %>
<%= f.label :send_any_time %><br />
<%= f.check_box :send_any_time %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
基本的なデバッグ印刷を試してください。 'params'には何が入っていますか? '@ signup'はどのような状態ですか?その条件がどのような価値を評価するかなど私のdevelopment.logファイルから –
'{" utf8 "=>"✓ "、" authenticity_token "=>" NPpMFeByG2U6 + yl8sE69lf6qI7HX/4GZmiCstBoB2AE = "、" signup "=> {" email_address "=>"フープ@ハイプ。 => "0"、 "send_any_time" => "0"}、 "コミット" => "サインアップの作成"} ' – rhodee