我在創建論壇時遇到了令人討厭的問題,我的form_for方法。每次我嘗試提交創建論壇時,我都會從Rails收到此錯誤。 param is missing or the value is empty: forum
Rails form_for援助:param丟失或值爲空
的問題是在我的forums_param方法:
def forum_params
params.require(:forum).permit(:id, :name, :position)
end
論壇部分不存在。下面的代碼是我的看法形式:
well.span11
.span7
= form_for @forum, url: forums_path, html: { method: :post } do |f|
= render partial: "form", locals: { f: f }
.actions
= submit_tag 'Create', { class: 'btn btn-primary btn-small' }
.clear
和部分它呈現:
%fieldset
%div{class: 'control-group'}
= label_tag :title, "Title (required)", class: 'control-label required'
%div{class: 'controls'}
= text_field_tag :name, nil, class: 'span8'
- if @forum.errors[:name]
%p{class: 'error'}#{@forum.errors[:name]}
%div{class: 'control-group'}
= label_tag :position, "Position", class: 'control-label'
%div{class: 'controls'}
= text_field_tag :position, nil, size: 5
%div{class: 'control-group'}
= label_tag :description, "Description", class: 'control-label'
%div{class: 'controls'}
= text_area_tag :description, nil, rows: 10, class: 'span10'
下面是控制器代碼:
def new
@forum = Forum.new
end
def create
@forum = Forum.new(forum_params)
if @forum.save
redirect_to forums_path, flash: { success: t('.success') }
else
redirect_to forums_path, flash: { error: t('.error') }
end
end
我不知道是什麼正在這裏。我已經實施了這些職位下描述的建議。
這裏有什麼問題?幫助將不勝感激。
你得到這個錯誤的頁面的網址/路徑是什麼? – miler350 2015-01-21 03:36:42