2016-07-03 3 views
0

私のレールアプリには簡単なクイズがあります。モデルはManTestであり、データ表の唯一の列はscoreで、参照関係はuserです。私は幾分か動作しているフォームを持っていますが、選択したラジオボタンに関係なく、scoreが0として記録されています。レールのラジオボタンの値が送信されない

<%= form_for @man_test do |f| %> 
    <h3> 
     <%= f.label "Which can you NOT score when playing American football?" %> 
     <%= f.radio_button :score, value: "1" %>Touchdown<br> 
     <%= f.radio_button :score, value: "0" %>Basket<br> 
     <%= f.radio_button :score, value: "1" %>Field Goal<br> 
     <%= f.radio_button :score, value: "1" %>Safety</h3> 
     <div class="text-center"> 
     <%= f.submit "Confirm I'm a Man", class: "btn-boring" %> 
     </div> 
    </h3> 
<% end %> 

man_tests#newページに次のように呼び出されます:

私のクイズは_test0.html.erb部分的形態である

<div class="hover-well col-xs-10 col-xs-push-1 col-sm-8 col-sm-push-2"> 
    <h1>Answer the following question to gain entry:</h1> 
    <%= render partial: 'man_tests/test00' %> 
</div> <!-- hover-well --> 

をそして、私は私のコンソールでManTest.lastを行うとき、私はこれを取得

[3] pry(main)> ManTest.last 
    ManTest Load (0.3ms) SELECT "man_tests".* FROM "man_tests" ORDER BY "man_tests"."id" DESC LIMIT 1 
=> #<ManTest:0x007f851acabdd0 
id: 3, 
score: 0, <<<<< SCORE IS ZERO REGARDLESS OF RADIO SELECTED 
user_id: nil, 
created_at: Sun, 03 Jul 2016 04:28:55 UTC +00:00, 
updated_at: Sun, 03 Jul 2016 04:28:55 UTC +00:00> 

誰でも私がwronが何であるか把握するのに役立つことができますかすべての選択肢が0点になるのは?

ADDITIONAL INFORMATION

はここManTestテーブルのスキーマです:

create_table "man_tests", force: :cascade do |t| 
    t.integer "score" 
    t.integer "user_id" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    end 

そして、ここでは私のman_tests_controllerです:

class ManTestsController < ApplicationController 
    layout false 

    def new 
    @man_test = ManTest.new 
    end 

    def create 
    @man_test = ManTest.new(man_test_params) 
    if @man_test.save && @man_test.score == 1 
     redirect_to home_index_path 
    elsif @man_test.save && @man_test.score == 0 
     redirect_to controller: :man_tests, action: :fail 
    else 
     render controller: :man_tests, action: :new 
    end 
    end 

    def fail 
    end 

    private 

    def man_test_params 
    params.require(:man_test).permit(:user, :score) 
    end 
end 
+0

コントローラも表示できますか?そしてDBの列 'score'のデータ型は何ですか? –

+0

@ArupRakshit、コントローラと 'man_tests'テーブルの' schema'を追加しました。 – Liz

+0

値が '' 1 ''であるラジオボタンを選択してフォームを送信すると、' log/development.log'で見ることのできるログが得られます。それも貼り付けることができますか? –

答えて

0

私はクイズのためにERBを変えてしまったし、それこのように働いた:

<%= f.label "Which can you NOT score when playing American football?" %> 
    <%= f.radio_button :score, 0 %> 
    <%= f.label :score, "Touchdown", value: 0 %><br> 
    <%= f.radio_button :score, 1 %> 
    <%= f.label :score, "Basket", value: 1 %><br> 
    <%= f.radio_button :score, 0 %> 
    <%= f.label :score, "Field Goal", value: 0 %><br> 
    <%= f.radio_button :score, 0 %> 
    <%= f.label :score, "Safety", value: 0 %><br> 
関連する問題