嗨我遇到了問題:「表單中的第一個參數不能包含零或爲空」。由於我是Rails的新受了我很難用現有的答案(仍然無法找到我的錯誤)請看看:RAILS 4表單中的第一個參數不能包含零或爲空
Showing /home/ubuntu/workspace/app/views/admin/categories/_form.html.haml where line #1 raised:
First argument in form cannot contain nil or be empty
Extracted source (around line #1):
= simple_form_for [:admin, @category], :html => {class: "form-horizontal"} do |f|
.form-group
= f.label :name, class: "col-sm-2 control-label"
.col-sm-10
= f.input_field :name, label: false, class: "form-control"
- if @category.id.present?
渲染:
= render 'form', :url => admin_categories_path(@category)
控制器:
class Admin::CategoriesController < AdminController
before_action :set_category, :only =>[:show, :edit, :destroy, :update]
def index
@categories = Category.all
respond_to do |format|
format.html
format.json {render json: @categories}
end
end
def show
respond_to do |format|
format.html
format.json { render json: @category }
end
end
def new
@category = Category.new
end
def create
@category = Category.new(category_params)
respond_to do |format|
if @category.save
format.html {redirect_to admin_categories_path, notice: 'Category created'}
else
format.html {render action: 'new', alert: 'Error while creating'}
end
end
end
def edit
end
def update
respond_to do |format|
if @category.update{post_params}
format.html {redirect_to admin_post_path, notice: "Category updated"}
else
format.html {render action: 'edit', alert: "Error while editing"}
end
end
end
def destroy
@category.destroy
respond_to do |format|
format.html {redirect_to admin_categories_path, notice "#{Category.title} deleted"}
end
end
protected
def get_category
@category = Category.find(params[:id])
end
def category_params
params.require(:category).permit(:title, :body)
end
end
出現這樣的情況,當你正在尋找新的或編輯行動? –
它發生在我去的路線: /管理員/類別/新 所以後 – Hoggie
錯誤是說'形式的第一個參數不能包含零或爲空提取源(繞行#1):'所以無論' category'爲零,或者將':admin'傳遞給'simple_form_for [:admin,@category]'正在評估爲零 –