I created a website: http://rails.project-midas.com/categories and when i want to add new category or update it I get an error.
The log says:
FATAL -- :
ActionView::Template::Error (undefined method `error_messages' for #<ActionView::Helpers::FormBuilder:0x000000031b5fa0>):
1: <%= f.error_messages %>
2: <p>
3: <%= f.label :name %><br />
4: <%= f.text_field :name %>
app/views/categories/_form.html.erb:1:in `_app_views_categories__form_html_erb___3155759666617831256_25435480'
app/views/categories/edit.html.erb:3:in `block in _app_views_categories_edit_html_erb__3036452290204433295_27619860'
app/views/categories/edit.html.erb:2:in `_app_views_categories_edit_html_erb__3036452290204433295_27619860'
CategoriesController:
class CategoriesController < ApplicationController
before_action :set_category, only: [:show, :edit, :update, :destroy]
# GET /categories
# GET /categories.json
def index
@all_categories = Category.find(:all, :order =>"name")
end
# GET /categories/1
# GET /categories/1.json
def show
end
# GET /categories/new
def new
@category = Category.new
@all_categories = Category.find(:all, :order => "name")
end
# GET /categories/1/edit
def edit
@category = Category.find(params[:id])
@all_categories = Category.find(:all, :order => "name")
end
# POST /categories
# POST /categories.json
def create
@category = Category.new(category_params)
respond_to do |format|
if @category.save
format.html { redirect_to @category, notice: 'Category was successfully created.' }
format.json { render action: 'show', status: :created, location: @category }
else
format.html { render action: 'new' }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /categories/1
# PATCH/PUT /categories/1.json
def update
respond_to do |format|
if @category.update(category_params)
format.html { redirect_to @category, notice: 'Category was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
# DELETE /categories/1
# DELETE /categories/1.json
def destroy
@category.destroy
respond_to do |format|
format.html { redirect_to categories_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_category
@category = Category.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def category_params
params.require(:category).permit(:parent_id, :name)
end
end
Category edit view file:
<h1>Zmiana kategorii</h1>
<% form_for(@category) do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<p>
<%= f.submit "Modyfikuj" %>
</p>
<% end %>
<%= link_to 'Pokaz', @category %> |
<%= link_to 'Wyswietl', categories_path %>
_form file:
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :parent_id %><br />
<%= f.collection_select :parent_id, @all_categories, :id, :long_name %>
</p>
Delete doesn't work either, in any page. All project file are in link