我不知道为什么它会向我显示此问题。显示/home/muba/muba/app/views/author/new.html.erb,其中第3行出现:
<%= form_for @author do |f| %>
<div class="form-group">
<%= f.label :first_name %><br/>
<%= f.text_field :first_name, class:'form-control' %><br/>
</div>
<% end %>
Author.rb控制器
class AuthorController < ApplicationController
def new
@page_title= 'Add new Author'
@author = Author.new
end
def create
end
def update
end
def edit
end
def destroy
end
def index
end
def show
end
def author_params
params.require(:author).permit(:first_name, :last_name)
end
end
但是我为我的“类别”页面所做的同样的事情正在起作用。代码是:
<%= form_for @category do |f| %>
<div class="form-group">
<%= f.label :name %><br/>
<%= f.text_field :name, class:'form-control' %><br/>
</div>
<%=f.submit "Submit", class:'btn btn-primary' %>
<%= link_to "Cancel", categories_path, class:'btn btn-default' %>
<% end %>
Category.rb控制器
class CategoriesController < ApplicationController
def new
@page_title= 'Add new Category'
@category= Category.new
end
def create
end
def update
end
def edit
end
def destroy
end
def index
end
def show
end
def category_params
params.require(:category).permit(:name)
end
end
我注意到您的第一行有问题,应该是
class AuthorsController < ApplicationController
代替
class AuthorController < ApplicationController
还要确保控制器的文件名是 authors_controller.rb
Ruby on Rails遵循语言惯例。检查Ruby和Rails命名约定
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句