Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

ruby on rails - After adding controller in active admin resource , validations error cannot be shown

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is because you just added blank create action in controller,

controller do
  def create
     create! { |success, failure|
     success.html do
       redirect_to admin_customers_path, :notice => "Resource created successfully."
     end
     failure.html do
       flash[:error] = "Error(s) : #{resource.errors.full_messages.join(',')}"
       redirect_to :back 
     end
   }
 end
end

Just remove blank create action or write it's implementation. Should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...