簡體   English   中英

在Ruby on Rails中創建新的模型對象時遇到麻煩-參數是符號嗎?

[英]Trouble creating a new model object in Ruby on rails - params are a symbol?

我收到了一個我不明白的怪異錯誤。 似乎當我嘗試創建一個新的模型對象時,有關參數的某些事情正在作為符號傳遞,而我對此無能為力。

我得到的錯誤是:

can't convert Symbol into Integer

控制器動作為:

def create
user_info = :params[:user]
if !user_info.value? ""
    if user_info[:password] == user_info[:password2] and user_info[:email] == user_info[:email2]
        user_info.delete("password2")
        user_info.delete("email2")
        @user = User.create!(user_info)
        @user = User.new(user_info)

        respond_to do |format|
            if @user.save
                format.html  { redirect_to(@user, :notice => 'User was successfully created.') }
            else
                format.html  { render :action => "new" }
            end
        end
end
flash[:warning] = "Please try again"
redirect_to home_index_path

  end

我正在嘗試使用“”提交屬性,但出現此錯誤。 當我刪除所指示的問題線user_info = :params[:user]和變更來講一切:params[:user]它仍然扔錯誤並指示的下一行的問題。

誰能看到原因?

user_info = :params[:user] 

至:

user_info = params[:user] 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM