Ruby on rails Rails嵌套表单更新时出现Ajax错误

Ruby on rails Rails嵌套表单更新时出现Ajax错误,ruby-on-rails,ajax,forms,Ruby On Rails,Ajax,Forms,在一个游戏中,我有一个10x10的网格,有100个方块,我试图为一个方块制作一个按钮,当点击该按钮时,会将方块的:user\u id更改为当前的用户id games/show.html.erb squares\u controller.rb Game.rb Square.rb User.rb 路线 当我点击购买一个正方形时,我得到的错误是ActionController::ParameterMissing in SquaresControllerbuy Param not found:squar

在一个游戏中,我有一个10x10的网格,有100个方块,我试图为一个方块制作一个按钮,当点击该按钮时,会将方块的:user\u id更改为当前的用户id

games/show.html.erb

squares\u controller.rb

Game.rb

Square.rb

User.rb

路线

当我点击购买一个正方形时,我得到的错误是ActionController::ParameterMissing in SquaresControllerbuy Param not found:square


我已经尝试了一段时间来解决这个问题,我相信我的路线现在是正确的,但是我在通过参数时遇到了麻烦。任何帮助都将不胜感激。

您没有经过方形物体

def square_params
**params.require(:square)**.permit(:xvalue, :yvalue, :user_id, :game_id, :boardposition)
end

通过表单以某种方式提供方形对象,或者删除强参数。

有没有办法将方形对象传入?或者,我不知道如何为“s”对象创建一个表单,因为它已经嵌套在squares数组中了
def show
    require 'enumerator'
    @user = current_user
    @game = Game.find(params[:id])
    @squares = Square.where(game_id:@game.id).all
end
def buy
    @square = Square.find(square_params)

    respond_to do |format|
        format.js
        if @square.update_attributes(user_id: current_user.id)
            format.html {redirect_to squares_path}
        else
            format.html {redirect_to :back}
        end
    end
end

private

def square_params
    params.require(:square).permit(:xvalue, :yvalue, :user_id, :game_id, :boardposition)
end
has_many :squares
has_and_belongs_to_many :users

validates :roomname, :roomtype, :teamone, :teamtwo, :gamedate, :squareprice, 
:maxsquares, :q1pay, :q2pay, :q3pay, :q4pay, presence: true

accepts_nested_attributes_for :squares
belongs_to :user
belongs_to :game
has_and_belongs_to_many :games
has_many :squares

accepts_nested_attributes_for :squares
 resources :games, :users, :squares

 get '/games/:id/join/' => 'games#join', as: :join
 get '/games/:id/buy/' => 'squares#buy', as: :buy

 match '/games/:id/', to: 'squares#buy', via: [:post] 
def square_params
**params.require(:square)**.permit(:xvalue, :yvalue, :user_id, :game_id, :boardposition)
end