Previously i have form and show method in active admin resource. At that time validation errors shown in forms. But now i have to write controller in resource , after adding no more validation errors. Am i doing something wrong. Below is my code.
ActiveAdmin.register PsychographicsQuestion do
config.clear_action_items!
permit_params :id , :title,:psychographics_question_type ,:expiry_date , :_destroy , psychographics_options_attributes: [:id,:title , :_destroy]
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs "Question" do
f.input :title , label: "Question"
f.input :psychographics_question_type, label: "Question Type" ,:prompt => 'Select Answer Type', :as => :select, :collection => DemographicsQuestion.demographics_question_types.keys.to_a
f.input :expiry_date, as: :datepicker, datepicker_options: { min_date: 0}
end
f.has_many :psychographics_options,heading: 'Options' do |item|
item.input :title
end
f.actions
end
show do
attributes_table do
row :title
row :psychographics_question_type
row :expiry_date
end
end
controller do
def create
question = PsychographicsQuestion.create(permitted_params["psychographics_question"])
if question.id != nil
PsychographicsQuestionFilter.create(@@filters)
filter_user = User.search(@@users)
for u in filter_user.result
FiltersMatching.create(:user_id => u.id, :psychographics_filters_id => @@filters.to_i , :psychographics_question_id => question.id)
#send_msg_through_gcm(u.to_i,"New PsychoGraphics question has been added.")
NotificationsDatum.create(:user_id => u.id , :msg => "New PsychoGraphics question has been added." , :category => NotificationsDatum.categories["PsychographicsQuestion"] , :status=>NotificationsDatum.statuses["Active"] , :viewed_status=>NotificationsDatum.viewed_statuses["NotViewed"] , :psychographics_question_id => question.id)
end
redirect_to admin_psychographics_question_path(:id => 93)
else
redirect_to new_admin_psychographics_question_path(:id => question.id)
end
end
end
filter :expiry_date
filter :created_at
end
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…