【发布时间】:2014-08-20 02:57:42
【问题描述】:
我制作了一个非常简单的 RESTful 应用程序,当我在表单字段中输入字符串并提交时,数据库保存 NULL 而不是输入字符串。
这是我的控制器:
def create
@song = Song.create(params[:title])
flash[:success] = "You have successfully created a new project!"
redirect_to "/songs/#{@song.id}"
end
这是我在 new.html.erb 文件中的表单:
<%= form_for(@song) do |f| %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<br>
<% end %>
【问题讨论】:
-
我觉得应该是
Song.create(params[:song])
标签: ruby-on-rails ruby database forms