사용자가 번호를 입력하고 양식을 아약스와 함께 제출하는 레일 앱에 양식이 있습니다. 모든 매개 변수가있는 경우 내 게임 컨트롤러에 새 게임이 만들어집니다. 두 개의 hidden_field_tags 매개 변수를 매우 잘 컨트롤러에 전달하지만 가장 중요한 매개 변수, 사용자 입력에서 얻은 매개 변수가 컨트롤러로 전달하지 않는 것 같습니다.레일 원격 양식 매개 변수가 컨트롤러로 전달되지 않음
내 양식 :
<%= form_for @game, :url => {:controller => "games", :action => "create" }, :html => { :role => 'form' }, remote: true, method: :post do |f| %>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="input-group">
<%= f.text_field :user_stake, class: 'form-control' %>
<span class="input-group-btn">
<%= f.submit 'Go', :html => { :type => "button" }, class: "btn btn-default" %>
</span>
</div>
</div>
</div>
<%= hidden_field_tag 'user_id', current_user.id %>
<%= hidden_field_tag 'jackpot_id', @jackpot.id %>
<% end %>
컨트롤러 :
before_action :game_params, only: [:create]
def create
@game = Game.new(game_params)
if @game.save
@jackpot = Jackpot.find(params[:jackpot_id])
ActionCable.server.broadcast 'jackpot_channel',
users: Jackpot.where(id: @jackpot.id),
pot: @jackpot,
user: User.find(@game.user_id),
game: @game,
stake: @game.user_stake.to_s
else
ActionCable.server.broadcast 'jackpot_channel',
error: @game.errors.full_messages
end
end
def new
@game = Game.new
end
private
def game_params
params.permit(:user_stake, :user_id, :jackpot_id)
end
무엇 @game에 입력하는 것은 내 마이그레이션에서 기본값으로 설정 한 0.0 user_stake로 저장되지됩니다 상관없이 . 내가 여기서 뭘 잘못하고 있는지 전혀 모르겠다. 어떤 아이디어? 감사!
지금 양식을 제출할 때 레일 서버에 힌트가 있습니까? –
'before_action : game_params, only : [: create]'를 제거하십시오. 그것은 낭비하는 시간/기억을 제외하고는 절대적으로 아무것도하지 않습니다. – max
DB 열 유형이란 무엇입니까? – max