view raw
Orsay Orsay - 7 months ago 29
Ruby Question

Undefined method when I loop to display a in form

I would like to have a list in my form with all my project statuses.

The field status exist in the database. When I run something like

it works fine but it doesn't when I loop into it.

When I run the following code I get :

undefined method `statuses' for Class...


<%= form_for [@context, @project], validate: true do |f| %>
<%= f.label "status" %>
<%=,{ |status| [I18n.t("#{status}"), status] %>


create_table "projects", force: :cascade do |t|
t.string "title"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "status"


You cannot use an assosciation directly on a Class so Project.statuses is wrong.

use select on Class and then map them

<%= form_for [@context, @project], validate: true do |f| %>
       <%= f.label "status" %>
       <%=,{ |status| [I18n.t("#{status}"), status]}.uniq %>