Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strong parameters for active admin #41

Open
sutherland007 opened this issue Oct 13, 2016 · 1 comment
Open

strong parameters for active admin #41

sutherland007 opened this issue Oct 13, 2016 · 1 comment

Comments

@sutherland007
Copy link

Update the active admin file (notice the comments in the code).
here is my example:

ActiveAdmin.register Survey::Survey do
  permit_params :name, :attempts_number, :description, :finished, :active #mandatory for rails 4 and newer versions of active admin
  menu :label => I18n.t("surveys")

  filter  :name,
          :as => :select,
          :collection => proc {
              Survey::Survey.select("distinct(name)").collect { |c|
                [c.name, c.name]
              }
          }
  filter :active #,
         #:as => :select,
         #:collection => ["true", "false"]
         # no needed activeadmin detects a boolean as yes or not automatically

  filter :created_at

  index do
    column :name
    column :description
    column :active
    column :attempts_number
    column :finished
    column :created_at
    actions #default_actions
  end

  form do |f|
    f.inputs I18n.t("survey_details") do
      f.input  :name
      f.input  :description
      f.input  :active #, :as => :select, :collection => ["true", "false"] no needed activeadmin detects a boolean input as checkbox
      f.input  :attempts_number
    end
    f.inputs I18n.t("questions") do
      f.has_many :questions do |q|
        q.input :text
        q.has_many :options do |a|
          a.input  :text
          a.input  :correct
        end
      end
    end
    f.actions #buttons
  end

end

There is another thing, the questions are not saving correctly, you can create a survey but when you save it, the questions were not saved, or when you try to save the survey a validation says " Survey without questions cannot be activated" in the active field and the questions that you've made, disappeared

I'm using active admin 1.0.0 pre 4
Rails 4.2.6
Ruby 2.20
the gsurvey gem "survey", "~> 0.1"

@sutherland007
Copy link
Author

i've solved it by adding this in the paramaters:
permit_params :name, :description, :active, :attempts_number, :questions_attributes => [:survey_id, :text], :options_attributes => [:question_id, :weight, :text, :correct]
please consider my solution for rails 4 support and activeadmin newer versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant