Search code examples
ruby-on-railsrubyactivescaffold

Ruby on Rails, ActiveScaffold and relatives in database


I have 2 tables: form, questions. Idea is very easy, every form have many question. Tables were maded

form = | id | title |

questions = | id | title | input | form_id |

and how you can guess the form_id is key of form id.

class FormsController < ApplicationController
 active_scaffold :form
end

class QuestionsController < ApplicationController
 active_scaffold :question
end

class Question < ActiveRecord::Base
 has_one :form
end

class Form < ActiveRecord::Base
 has_many :question
end

and I want to make an activescaffold (question) with select with avalable forms. Now I can only input the id of form, but not choice it by dropdown menu. How should I configure rails or activescaffold?

Thanks. Sorry for my English :)


Solution

  • You need to add some configuration to your controller.

    class QuestionsController < ApplicationController
      active_scaffold :question do |config|
        config.columns = [:id, :title, :input, :form_id]
        config.columns[:form_id].ui_type = :select
      end
    end