Ruby on Rails, ActiveScaffold and relatives in the database

I have 2 tables: form, questions. The idea is very simple, there are many questions in each form. Tables have been engraved.

form = | id | title |

questions = | id | title | entrance | form_id |

and as you can guess, form_id is the form identifier key.

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 activescaffold (question) with a selection with available forms. Now I can only enter the form identifier, but not select it from the drop-down menu. How do I set up rails or activescaffold?

Thanks. Sorry for my English:)

+3
source share
3 answers

You need to add the configuration to the 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
+4

, activescaffold , : Dropdown , , role_to. , :

. . allesklar:

class Form < ActiveRecord::Base
 has_many :questions
end

class Question < ActiveRecord::Base
 belongs_to :form
end

"belongs_to", : form

, , , ____, -

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

, "def to_label", ActiveScaffold , .

+4

I'm not sure about active_scaffold, but there are a few errors in your relationship statements in the form and model of the question. I think this is what you want:

class Form < ActiveRecord::Base
 has_many :questions
end

class Question < ActiveRecord::Base
 belongs_to :form
end

Hope this helps.

0
source

Source: https://habr.com/ru/post/1708448/


All Articles