I have hstore as one of the data types for my backend and it seems like formtastic hasn't supported this data type yet. Help :-(?
This is the error that I got: Unable to find input class for hstore
https://github.com/gregbell/active_admin/issues/2032 seems to be the same issue. I think you need to implement a custom input handler yourself. http://stackoverflow.com/questions/14605710/filter-activeadmin-with-hstore would help.
What exactly do you want? Do you want preset keys that you can set the values for? Or do you want to be able to save arbitrary keys and values?
For the more dynamic form, check out http://railscasts.com/episodes/403-dynamic-forms
Oh ok, these leads are enough for me to get moving on. Thanks.
It'd be really useful to either add a Formtastic Input type for hstore into Active Admin, or to have a wiki page describing the options available. Think you'd be up to the task @rebyn?
(ping)
Okay, well I'm going to close this for now
Late bird to the party.
A sensible "input type" for hstore is a two-column table of editable cells.
Yeah. I'm currently implementing something similar for work, so I'll create a PR for this eventually.
@seanlinsley can you tell me the gem for the input type for a hstore? I would need it.
@orbanbotond -> https://github.com/diogob/activerecord-postgres-hstore
@seanlinsley I would need an input for either formtastic or simple_form
Nothing yet exists, hence why this ticket is open.
Ping. I for one would love for this feature to work - it probably makes the difference between using and not using active_admin for us.
Has the gem supported seeing the input form with hstore fields at all? We can just temporarily disable edits (on hstore fields) for now to have the final working version later. @seanlinsley
Is this currently being worked on?
Why was this closed? It seems as though the problem is not fixed and no pull request has been made. I am new to Rails so I wouldn't know where to start with a PR but definitely need this functionality.
? This ticket isn't closed. I closed the ticket you made as a duplicate of this one.
My apologies...any progress? I was able to use the following form to edit HStore values however it cannot add another HStore key/value pair, only edit a current pair.
ActiveAdmin.register Question do
form :partial => "form"
end
<%= semantic_form_for [:admin, @question] do |f| %>
<%= f.inputs :content %>
<%= f.fields_for :choices do |choice| %>
<%= f.object.choices.try(:each) do |key, value| %>
<%= choice.input key, :input_html => {:value => value } %>
<% end %>
<% end %>
<%= f.actions :submit %>
<% end %>
I ended up using the following changes to edit hstore fields. It uses eval and isn't great for user input in all scenarios since they will have to input the hstore as {'1'=>'stuff','2'=>'stuff2'} but it does work and allows you to add key/value pairs and not just edit them. Also, my mark up is not all showing up because I am missing how to indent for code.
ActiveAdmin.register Question do
form :partial => "form"
controller do
def update
question = Question.find(params["id"].to_i)
unless params["question"]["choices"].first.last == ""
new_choice = eval(params["question"]["choices"].first.last)
question.choices = new_choice
question.save!
end
params["question"].delete("choices")
super
end
end
end
and the form I created ...
<%= semantic_form_for [:admin, @question] do |f| %>
<%= f.inputs :content, :answer_type, :question_order %>
<fieldset class="inputs">
<%= f.fields_for :choices do |choice| %>
<ol>
<li class="string input optional stringish" id="question_choices_input">
<label class="label" for="question_choices">Answers/Choices</label>
<%= choice.input f.object.choices.inspect, :input_html => {:choices => :choices } %>
<% end %>
</ol>
</fieldset>
<%= f.actions :submit %>
<% end %>
@MicFin can you please wrap code with "```" before and after the code?
here editor hstore fields like 邪 json that use jsoneditor.js
https://github.com/wild-r/activeadmin_hstore_editor
i will be grateful for your feedback
@wild-r
Remove logger from https://github.com/wild-r/activeadmin_hstore_editor/blob/master/lib/activeadmin/resource_dsl.rb#L11
Also update some assets with 2 spaces.
Haven't tested at all on any application, but it would be good for some cases.
@wild-r I tried to use the gem, and though it got me past the initial error Unable to find input class for hstore
. When I update a resource, I get an error
NoMethodError in Admin::FormJobsController#update
I have no idea what's going on here.
@dmitry Did you have a chance to get this to work?
@MicFin Did both of your active admin/hstore suggestions work? Neither are working for me. I'm assuming that "choices" is the column in the questions table that has a datatype of hstore. And "content" is just another column in the same table.
My form looks like this:
<%= semantic_form_for [:admin, @form_job] do |f| %>
<%= f.inputs :organization %>
<%= f.fields_for :metadata do |data| %>
<%= f.object.metadata.try(:each) do |key, value| %>
<%= data.input key, :input_html => {:value => value } %>
<% end %>
<% end %>
<%= f.actions :submit %>
<% end %>
And it adds the metadata (equivalent to your "choices") outside of the form.
@miriamdeana Yes you are correct in your assumptions. I would recommend looking at the line in my code
f.object.choices.inspect,
You have just a key being passed there and also your value is singular where I had to make my plural to match the fields_for
:input_html => {:choices => :choices }
My form...
<%= semantic_form_for [:admin, @question] do |f| %>
<%= f.inputs :content, :answer_type, :question_order %>
<fieldset class="inputs">
<%= f.fields_for :choices do |choice| %>
<ol>
<li class="string input optional stringish" id="question_choices_input">
<label class="label" for="question_choices">Answers/Choices</label>
<%= choice.input f.object.choices.inspect, :input_html => {:choices => :choices } %>
<% end %>
</ol>
</fieldset>
<%= f.actions :submit %>
<% end %>
@wild-r thx for gem. It helped for me
Using a gem for supporting HStore looks to me as the best/elegant way.
@MicFin : I am not able to edit the data. The form loads up all correctly. But when I edit the data I get unpermmitted params error, though I have added it to the permitted params list.
Here is my code
permit_params :name,:current_address
form do |f|
f.input :name
f.fields_for :current_address do |current_address|
f.object.current_address.try(:each) do |key, value|
current_address.input key, :input_html => {:value => value }
end
end
end
I get this error Unpermitted parameters: current_address
@aaditij-webonise If you can post the rb file and whole view I might be able to help. Maybe open a www.stackoverflow.com question as well.
@McFin, here is the rb file:
ActiveAdmin.register Provider do
permit_params :dob, :current_address
menu parent: 'User'
config.sort_order = 'id_asc'
actions :all, except: [:new]
filter :mobile_number
filter :id
index do
selectable_column
column :id
column :mobile_number
column :name
column :gender
column :dob
column :current_address
actions
end
form do |f|
f.inputs 'Provider Details' do
f.input :dob, as: :datepicker
f.fields_for :current_address do |current_address|
current_address.input :full_address,
input_html: {value: f.object.current_address.
try(:[], 'full_address')}
end
end
f.actions
end
end
Here is the stackoverflow question I created for it: http://stackoverflow.com/questions/35218336/active-admin-form-with-hstore-column-unpermitted-param-error
@aaditij-webonise the problem is your permitted params:
permit_params :name, :current_address
That won't work because of the nested values. You either need to do this:
permit_params :name, current_address: []
Or this:
permit_params :name, current_address: {}
Nested attribute must be defined or used blank array in case you are not sure about number of parameter.
Quick'n'dirty fix for this is to create a Formtastic input in app/inputs/hstore_input.rb
:
class HstoreInput < Formtastic::Inputs::TextInput
end
For people with JSONB columns, try this
Most helpful comment
Quick'n'dirty fix for this is to create a Formtastic input in
app/inputs/hstore_input.rb
: