简体   繁体   English

在Ruby on Rails中创建新的模型对象时遇到麻烦-参数是符号吗?

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

I'm getting a weird error I don't understand. 我收到了一个我不明白的怪异错误。 It seem that when I try to create a new model object, something about the params is being passed are being as symbol and I can't do anything with them. 似乎当我尝试创建一个新的模型对象时,有关参数的某些事情正在作为符号传递,而我对此无能为力。

The error I'm getting is: 我得到的错误是:

can't convert Symbol into Integer

The controller action is: 控制器动作为:

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

I'm trying to submit attributes with "", but I get this error. 我正在尝试使用“”提交属性,但出现此错误。 When I removed the indicated problem line user_info = :params[:user] and changed everything in terms of :params[:user] it still threw the error and indicated the next line as the problem. 当我删除所指示的问题线user_info = :params[:user]和变更来讲一切:params[:user]它仍然扔错误并指示的下一行的问题。

Can anyone see why? 谁能看到原因?

Turn

user_info = :params[:user] 

to: 至:

user_info = params[:user] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM