0

I get this error even though i defined @class = Class.all1

Controller code:

    class ClassesController < ApplicationController
    before_action :authenticate_user!, except: [:index, :show]
    before_action :set_class, only: [:show]
    def index
        @classes = Class.all
    end

    def show 

    end

    def new
        @class = Class.new
    end

    def create
        @class = Class.new  class_values
        @class.user_id = current_user.id
        if @class.save
            redirect_to  classes_path
        else
            render :new
        end
    end
end

And form code:

            <%= form_for @class do |f| %>

                <div class="form-group">
            <%= f.label :name %>
            <%= f.text_field :name, class: 'form-control' %>
                </div>

                <div class="form-group">
            <%= f.label :opis%>
            <%= f.text_area :opis, class: 'form-control'%>
                </div>



            <%= f.submit "Post", class: 'btn btn-outline-primary'%>
            <%= link_to  "Back", classes_path, class: 'btn btn-outline-secondary' %>
        <% end %>

I database i hvae table named classes with atributes user_id and name and opis(description)

2 Answers2

1

Your Class model is colliding with Ruby Class object. You need to choose a different name for your model.

Rolandas Barysas
  • 310
  • 1
  • 2
  • 12
0

Class is not a good name for table, this is reserved word for Rails/Ruby and in other programming languages too. Consider changing it to something different

nuaky
  • 2,036
  • 1
  • 14
  • 20