undefined method 'binary_input' error with formtastic - ruby-on-rails

I just made a change to my database, adding a 'description' with a data type of blob.
I've added the :description to my attr_accessible in my model, and added :description to my form, so it looks like
<%= form.inputs :title, :image, :description %>
When I run the form, I get
undefined method `binary_input' for #<Formtastic::SemanticFormBuilder:0x5876568>
I have absolutely no idea where to even start debugging this. If I remove :description from the form, everything is fine. I see in my database that the field was added no problem and has a type of blob.
Any suggestions on how to fix this??
I'm using Ruby 1.92 on rails 3.
----------------------------------UPDATE-------------------------------------------
I was suspicious that the BLOB type was the cause of this problem, so I altered the column type to string, and now it works.
Unfortunately, I'm expecting the descriptions to be longer than the string field in the database allows.
Anybody else have issues using blob??
I have another blob field in my db which works without issue.
Thanks

Related

Acts As Taggable On with Rails Admin

I have installed the gem acts-as-taggable-on, everything is working well with my model, but I would like to use Rails Admin and this is where I have a problem...
In the form new or edit, I would like to display the field Tags with 2 columns, the first one with the list of all the tags already recorded and the second with tags I want to use. For now, I just have a simple field, where I can enter tags with comma.
I have added the code below in rails_admin.rb:
config.model Recipe do
edit do
field :title
field :url
field :prep_time
field :cook_time
field :serve
field :picture
field :publisher
field :ingredient_lines
field :ingredients
field :tag_list do
html_attributes do
{:style => "width:90%"}
end
end
end
end
Just to give you a idea of what I want, here are a screenshot.
Screenchot link
Thank you for your help :)
Problem solved. I have created my own tag model, no everything is working well.

Updating multiple records in a single submit? - Rails 3

I'm a newbie to rails and am having some difficulty...
I have a page displaying a list of records in a table and would like for the user to be able to make changes, submit the form, to run validation and persist the data.
This is what I have so far:
View:
- #people.each do |p|
%tr
%td
%input{:type => "hidden", :name => "person_id[]", :value => p.id}
%input{:name => "firstname[]", :value => p.firstname}
%td
%input{:name => "lastname[]", :value => p.lastname}
Example parameters being posted to the controller:
"person_id"=>["12", "13", "14"],
"firstname"=>["john", "joe", "mary"],
"lastname"=>["smith", "bloggs", "jane"],
At this point I am scared, because I am no longer bound to an active record. Instead I feel myself wanting to write some messy code to loop over the person_id array to see what has changed and write any changes back.
This feels bad because I have to explicitly compare each field, also if something fails due to a validation error half way through how should I rollback any changes and display the messages to the user?
I'm hoping that due to my rails ignorance this whole approach is wrong and I am missing a trick. Does anyone have any suggestions for how to approach this problem?
I suppose you have an association setup between people model and person model, by looking at the hidden person_id field in your view code.
If your associations are rightly setup, use
accepts_nested_attributes_for
and follow the Rails guides for association basics.
At this point of time, I can only help you this much, as not much information is provided in your question.

observ_field with collection_select on rails 2.3.8?

I'm developing project on rails 2.3.8 and I need to observe field on drop down menu which develop using collection select. Please can some one explain how to observe field ?
My collection select code is like this
<%= collection_select("event", "trainer_id", #trainers , :id, :name, {:prompt => true}) %>
And I don't know how to use observe field for this. So please can some one explain about this ?
Related: Auto populate a text field based on another text field
observe_field(field_id, options = {})
Observes the field with the DOM ID specified by field_id and calls a callback when its contents have changed. The default callback is an Ajax call. By default the value of the observed field is sent as a parameter with the Ajax call.
Read this details: http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/observe_field

form not saving to database in rails

I currently have a form:
<%= f.label(:price) %> <br/>
<%= f.text_field(:price, :value => number_to_currency(#object.price)) %>
I changed my migration from using float to using decimal:
change_column :object, :price, :decimal, :precision => 5, :scale => 2
On my view, I called it using:
<%= #object.price %>
For some reason, whenever I make a change to the form or in the console, it never saves the value and keeps it at $0.00 regardless of what i change it to. In the view, it always shows up as '0.0'. I am not sure what the problem is.
Do you have a table named object or objects or is this just an example?
If not, check your price column to make sure the migration worked properly.
If you do have a proper column type in your table, check to see if you're using attr_accessible in the Object class (and that price is included).
Also, if you are using Object as your class name, you may have some other issues here and I'd advise against it.
EDIT
number_to_currencymay prepend a $ in front of your cost, make sure you're entering your price without any currency before it or else I believe this would also result in 0.0 (can't parse decimal '$123.00', but can parse '123.00'

Formtastic non-model form, integration with external site, override/specify the input ID values

I'm using formtastic to collect information from a form and post dirctly to an external site.
I have no problem generating the form itself. However, since this is being submitted to an external site, they require that each input field have the specific IDs they specify, eg email or last_name -- not the closest Formtastic form, eg _email_input or _last_name_input.
I've looked at the Formtastic v1.2.3 code and I'm 90% sure the answer is "sorry, can't do that." I figured it couldn't hurt to check if I'm missing something. I would like some way to specify the ID completely, as in:
= semantic_form_for('', :url => "https://external_site.com/handler, :method => "post") do |form|
= form.input :last_name, :id => "last_name"
[etc]
Is this possible?
(I will note that I recognize that another, arguably superior approach would be to create an appropriate controller, sanity check the parameters locally, and dispatch the remote call from within the app only when it's well formed; however, that's not what I'm trying to do at the moment.)
Firstly i think you need to use semantic_fields_for for non-model forms. Next, to pass ids to each field, you can use the input_html options to specify them. for eg
form.input :email, :input_html => {:name => 'email', :id => 'email' }

Resources