Question

I am playing with RailsAdmin on Rails 4. And I have very simple case (two models, Event belongs to Idea).

Code:

class Idea < ActiveRecord::Base
end

class Event < ActiveRecord::Base
  belongs_to :idea

end

Schema

  create_table "events", force: true do |t|
    t.string   "location"
    t.integer  "idea_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "events", ["idea_id"], name: "index_events_on_idea_id"

  create_table "ideas", force: true do |t|
    t.string   "title"
    t.text     "descrption"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

And I am seeing this. And I can't figure out why does it show both drop down to choose idea and additional numeric editbox?

enter image description here.

Was it helpful?

Solution

RailsAdmin heavily relies on your relationships to dynamically generate the forms. Aside from that, you would have encountered other issues down the line if you didn't map your relationships from both models.

class Idea < ActiveRecord::Base
  # missing
  has_many :events
end

class Event < ActiveRecord::Base
  belongs_to :idea
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top