gpt4 book ai didi

ruby-on-rails - "no implicit conversion of Symbol into String"尝试创建新记录时

转载 作者:数据小太阳 更新时间:2023-10-29 08:31:38 26 4
gpt4 key购买 nike

当我尝试创建新记录时出现错误no implicit conversion of Symbol into String,我不明白这是因为所有数据都是由字符串组成的。

在我的 Controller 中:

def new
@account = Account.new
end

def create
@account = Account.new(account_params)
if @account.save
redirect_to(:action => 'index')
else
render('new')
end
end

private
def account_params
params.require(:account).permit(:username, :firstname, :lastname, :organisation, :phonenumber, :avatar, :about, :verified)
end

形式很简单:

<%= form_for(@account) do |f| %>
<div>
<%= f.label :username %><br>
<%= f.text_field :username %>
</div>
<div>
<%= f.label :firstname %><br>
<%= f.text_field :firstname %>
</div>
<div>
<%= f.label :lastname %><br>
<%= f.text_field :lastname %>
</div>
... more of the same...

<div class="actions">
<%= f.submit %>
</div>
<% end %>

和迁移文件:

class CreateAccounts < ActiveRecord::Migration
def change
create_table :accounts do |t|

t.string :username
t.string :firstname
t.string :lastname
t.string :organisation
...more of the same, all strings...
end
add_index :accounts, :username, unique: true
end
end

我正在使用 Rails 3.2 和 Ruby 2.1.5。

最佳答案

我找到了解决方案:在 Controller 中我不得不改变

@account = Account.new(account_params)

@account = Account.new(params[:account])

关于ruby-on-rails - "no implicit conversion of Symbol into String"尝试创建新记录时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28266979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com