0
votes

I am using the administration framework 'active admin' to build a RubyOnRails Application. I have a Dropdown Menu that looks like this in my form:

  form do |f|    

    f.inputs do
      f.input :art, as: :select, :include_blank => "Bitte wählen!", label: 'art', :collection => ["Fachobjekt", "Gruppe", "Externes Dokument"]
    end
    f.actions    
  end

Now in my controller I want to check the selected value. I tried:


controller do
  after_save :update_object

  def update_object(guid)
      if params[:art].values == 'Fachobjekt'
        # do stuff
      end
  end
end

I chose 'Fachobjekt' in my Dropdown but I get the NoMethodeError "undefined method 'values' for nil:NilClass", so the params[:art] is null.

My question is: what is the correct syntax to get the selected value of my f.input-field? I appreciate any hint!

[:root_tables] ist the model name. I put it before [:art] like params[:root_tables][:art] but same error.

2
What is the model name?Roman Alekseiev
[:root_tables] ist the model name. I put it before [:art] like params[:root_tables][:art] but same error.Sörenius
Hm. It should return proper params. Do you use permitted params? So if you sanitize params you would be able to access them as permitted_params[:root_tables]Roman Alekseiev
so, maybe do some basic debugging using binding.pry or similar. place it on the very top of method and see what params you are receiving. or Even simple print of them (actually rails are printing params on every request) post those params, then it might be easier to find reasonblazpie

2 Answers

0
votes

Put a

raise params.inspect

just before the

if params[:art]

line. You should be able to identify where the posted information resides in the params.

0
votes

Thanks for all of your hints! Especially the hints for debugging with binding.pry helped me. I use f.select instead of f.input now:

  form do |f|    

    f.inputs do
      f.select :art, ["Fachobjekt", "Gruppe", "Externes Dokument"], :prompt => 'Bitte wählen! '
    end
    f.actions    
  end

For select the params[:root_table][:art] is working:

controller do
  after_save :update_object

  def update_object(guid)
      if params[:root_table][:art] == 'Fachobjekt'
        # do stuff
      end
  end
end

When i use f.input, [:art] is not even showing up when doing binding.pry or raise params.inspect. With f.select it does. However, at least it's working now, so thanks!