爲Rails大師簡單的問題。爲什麼我必須使用下面的語句來插入一個新Mongoid文件:PARAMS [:視頻] [:描述]我VideosController以下create方法?爲什麼我不能使用POST表單中的params [:description]?如果我使用它,價值變成零。回報率:Mongoid和形式創建哈希
def create
@video = Video.new(
:title => params[:video][:title],
:description => params[:video][:description]
)
if @video.save
render 'success'
else
render 'error'
end
end
這裏是Video.rb類:
class Video
include Mongoid::Document
field :title, type: String
field :description, type: String
validates_presence_of :title
validates_presence_of :description
acts_as_url :title
end
而且finaly表單視圖:
<%= form_for @video do |f| %>
<%= f.label :title %>
<%= f.text_field :title %>
<p/>
<%= f.label :description %>
<%= f.text_field :description %>
<%= submit_tag("Enqueue video") %>
<% end %>
我不太明白爲什麼表單輸入的視頻[說明]而不僅僅是如預期的那樣描述:
<label for="video_title">Title</label>
<input id="video_title" name="video[title]" type="text" />
<p/>
<label for="video_description">Description</label>
<input id="video_description" name="video[description]" type="text" />
在模型不關心的'params'(例如':action',該按鈕被按下......)的頂層也會有一堆東西。 –