How I can make this form in activeadmin?
<%= form_for(#album, :html => {:multipart => true}) do |f| %>
.....
<div class="field">
<%= f.label :apellido %><br />
<%= f.text_field :apellido %>
</div>
<div class="field">
<p>Hijos</p>
<%= f.fields_for :hijos do |builder| %><br /><br />
<%= builder.label :nombre, 'Nombre Hijo' %><br />
<%= builder.text_field :nombre %><br />
<%= builder.label :apodo, 'Apodo Hijo' %><br />
<%= builder.text_field :apodo %><br />
<%= builder.label :hijo_id, 'favorito' %>
**<%= f.radio_button :hijo_id, builder.object.id %>**
<% end %>
</div>
I need put the option of hijo_id inside the for of :hijos
Try with :
f.input :avatar_item_id, :as => :boolean, :value => app_f.object.id
But not work.
Thanks
This should work once you register the Album model as an ActiveAdmin resource:
form :html => {:multipart => true} do |f|
f.inputs "Principal" do
f.input :apellido
end
f.inputs "Hijos" do
f.has_many :hijos do |h|
h.input :nombre
h.input :apodo
h.input :favorito, :as => :check_box
end
end
f.buttons
end
If you want to mark a child as a favorite, you need a boolean favorito field in the hijos table, not a hijo_id field.
Related
Currently i have working devise form, but now i'm trying to add some client side validation with parsley-rails.
How to include 3 argument in form_for helper if i can include only 2 arguments
I'm using
Rails 4.1.8
ruby 2.1.5p273
So this is my form:
<%= form_for(resource as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username, autofocus: true %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email %>
</div>
<div class="field">
<%= f.label :password %>
<% if #validatable %>
<em>(<%= #minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<hr>
<div>
<%= f.label :country_id %>
<%= f.select(:country_id, options_from_collection_for_select(Country.all, :id, :name)) %>
</div>
<br><br>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
and this are parsley-rails instructions:
And then I added the following to the form I wish to validate on
<%= form_for :user, :html => {:"data-validate" => 'parsley'} do |user| %>
When i'm trying to include this line i always get error even after i deleted that :html => {:"data-validate" => 'parsley'} line
wrong number of arguments (3 for 2)
Extracted source (around line #3):
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :validate => true) do |f| %>
<%= devise_error_messages! %>
<div class="field">
I found out how to include this.
This is how form_for should look like
<%= form_for(resource, :html => {:'data-validate' => 'parsley'}, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
....
<% end %>
I'am using select_tag and when I update selected value is not stored
when i update :name, :tag value get first option
edit.html.erb
<%= form_for(#name) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :lname%><br />
<%= f.text_field :lname%>
</div>
<div class="field">
<%= f.label :tag %><br />
<%= f.select :tag, "<option>1</option><option>2</option><option>3</option><option>4</option>".html_safe %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Solution
<%= f.collection_select(:tag, [1,2], :to_i, :to_s, :prompt => 'Categories') %>
Maybe?
= f.select :tag, (1..4).to_a, :prompt => '---'
try to use select tag from this link
select_tag
<%= select_tag "tag", "<option>1</option><option>2</option>" %>
Try this
<%= f.select "tag", "<option value="1">1</option><option value="2">2</option></select>".html_safe %>
read http://ashleyangell.com/2009/11/form-select-helper-in-ruby-on-rails/
Solution
<%= f.collection_select(:tag, [1,2], :to_i, :to_s, :prompt => 'Categories') %>
How do I set the id attribute in my drop down boxes?
Here is the part of my form in question:
<%= f.fields_for :items do |builder| %>
<%= builder.label :description %><br />
<%= builder.text_field :description %><br />
<%= builder.label :material %><br />
<%= builder.select :material, #letters.map { |l| [l.material, l.material] }, :id => "material_field" %><br />
<%= builder.label :height %><br />
<%= builder.select :height, #letters.map { |l| [l.height, l.height] }, :id => "height_field" %><br />
<%= builder.label :thickness %><br />
<%= builder.select :thickness, #letters.map { |l| [l.thickness, l.thickness] }, :id => "thickness_field" %><br />
<%= builder.label :quantity %><br />
<%= builder.text_field :quantity, :id => "quantity_field" %>
<%= builder.link_to_remove "Remove this item" %>
<% end %>
The :id => "quantity_field" method works for text fields, but not for the select fields. Viewing the HTML source I am getting an id of "estimate_items_attributes_0_material" for the material text box.
This is a strange inconsistency. Any help will be greatly appreciated.
There is a parameter between the possible choices and the html options. So you have to do this :
<%= builder.select :thickness, #letters.map { |l| [l.thickness, l.thickness] }, {}, :id => "thickness_field" %>
You can find the doc here : http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-select
And this one can also be helpful :
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select
I am having trouble using the Ruby Gem paperclip. I followed the instructions in the ReadMe but I cannot seem to get it to actually load my images. Here is my edit form:
<% form_for :user, #user, :html => { :multipart => true } do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :expertise %><br />
<%= f.text_area :expertise, :class => "expertise" %>
</div>
<div class="field">
<%= f.label :occupation %><br />
<%= f.text_field :occupation %>
</div>
<div class="field">
<%= f.label :city %><br />
<%= f.text_field :city %>
</div>
<div class="field">
<%= f.label :state %><br />
<%= f.text_field :state %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<%end%>
Yet when I try to save I keep getting this error: No route matches "/users/4/edit"
What is the problem
The error is telling you that there's no /users/4/edit route. What does your config/routes.rb look like? If there's a line like:
resources :users
Then, try changing that first line to:
form_for #user
Instead of:
form_for :user, #user
Also, I don't see a file_field in there anywhere so I don't think this question is about Paperclip?
My view:
<h1>New Address</h1>
<% form_for #address, :url => new_address_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
<%= f.submit "Add Address" %>
<% end %>
Partial... nothing special
<%= form.label :number %><br />
<%= form.text_field :number %><br />
<br />
<%= form.label :street %><br />
<%= form.text_field :street %><br />
<br />
<%= form.label :city %><br />
<%= form.text_field :city %><br />
<br />
<%= form.label :state %><br />
<%= form.text_field :state %><br />
<br />
<%= form.label :zip_code %><br />
<%= form.text_field :zip_code %><br />
<br />
<br />
my error:
ActionController::MethodNotAllowed
Only get, put, and delete requests are allowed.
MethodNotAllowed seems to come from resource-based routing. Resource-based routing requires distinct method names to match actions. In your case, you should supply :method => :post in form_for, something like that:
<% form_for #address, new_address_path, :method => :post) do |f| -%>