ruby on rails - undefined local variable or method `template_params' for TemplatesController:Class -
i tried create model named template
, when tried open localhost:3000/templates/new
, got undefined method error in templatescontroller
, private method doesn't work, why?
templates controller:
class templatescontroller < applicationcontroller def new @template = template.new 4.times { @template.fields.build} end def edit @template = template.find(params[:id]) end def show @template = template.find(params[:id]) end def create @template = template.new(template_params) if @template.save redirect_to root_path end end def update end private def template_params params.require(:template).permit(:name, fields_attributes: [:id, :name,:template_id]) end end
templates/new.html.erb:
<div class="container"> <%= form_for(@template) |f| %> <%= f.label :name %> <%= f.text_field :name %> fields: <ul> <%= f.fields_for :fields |field| %> <li> <%= field.label :name %> <%= field.text_field :name %> </li> <% end %> </ul> <% end %> </div>
error:
actioncontroller::routingerror (undefined local variable or method `template_params' templatescontroller:class): app/controllers/templates_controller.rb:27:in `<class:templatescontroller>' app/controllers/templates_controller.rb:1:in `<top (required)>' rendering /users/xi/.rvm/gems/ruby-2.2.2/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout rendering /users/xi/.rvm/gems/ruby-2.2.2/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Comments
Post a Comment