I made a form, but I don't know how to collect data from it and after pressing submit button redirect user to adding/fill.erb file, here is my form:
file: adding/counter.erb
<%= simple_form_for :counter do |f| %>
<%= f.input :first_name, :collection => 0..10 , :prompt => "How many?" %>
<%= f.input :last_name, :collection => 0..10 , :prompt => "How many?" %>
<%= f.input :city, :collection => 0..10 , :prompt => "How many?" %>
<%= f.input :postal, :collection => 0..10 , :prompt => "How many?" %>
<%= f.input :street, :collection => 0..10 , :prompt => "How many?" %>
<%= f.input :job, :collection => 0..10 , :prompt => "How many?" %>
<%= f.input :role, :collection => 0..10 , :prompt => "How many?" %>
<%= f.button :submit, 'next step', :style => "margin-top: 20px;" %>
<% end %>
I know it is a lame question, but I'm working on it for several hours and I don't know what to do:/
I'm not entirely clear, but it sounds like your trying to set the URL the form is posted to? If so, you should be able to do this:
<%= simple_form_for :counter, :url => {:controller => "counter", :action => "fill} do |f| %>
Related
In Rails 3.2 - I sometimes use :input_html on forms.
For example:
<%= f.input :assign_client, :label => 'Charge Client?', :input_html => {:checked => true} %>
If the user unchecked the box and submits the form and there are some validation errors, the check box gets checked again.
Is there a way to leave it unchecked?
Thanks for your help!
UDPATE1
I changed the code to this:
<% if params.has_key?(:assign_client) %>
<%= f.input :assign_client, :label => 'Charge Client?' %>
<% else %>
<%= f.input :assign_client, :label => 'Charge Client?', :input_html => {:checked => true} %>
<% end %>
But, that didn't work.
The params hash will contain the assign_client key if the checkbox was checked by the user. So, you could do something like this:
<%= f.input :assign_client, :label => 'Charge Client?', :input_html => { :checked => params.has_key?(:assign_client) } %>
I'm just trying to send email from within my application. For some reason, the email isn't being sent. Am I missing a step? Here is the contact_us documentation. I followed it exactly. https://github.com/jdutil/contact_us. How can I get it to mail?
Here is my view:
<div class="container">
<h2><%= t('.contact_us') %></h2>
<%= simple_form_for #contact, :url => contacts_path do |f| %>
<%= f.input :name, :label => t('.name') if ContactUs.require_name %>
<%= f.input :email, :label => t('.email') %>
<%= f.input :subject, :label => t('.subject') if ContactUs.require_subject %>
<%= f.input :message, :as => :text, :label => t('.message') %>
<%= f.button :submit, :value => t('.submit'), :alt => t('.submit'), :id => 'contact_us_contact_submit', :title => t('.submit') %>
<% end %>
</div>
I also set config.mailer_to = "drichards2013#gmail.com."
When I submit the form, I receive a notification that the email was successfully sent.
I want to add delete button in actions. but all it does is js goback. I tried <%= f.actions %> didn't show the delete button. below is my effort to add it manually.
<% if can? :update, #parking_branch %>
<%= semantic_form_for #parking_branch do |f| %>
<%= f.semantic_errors %>
<%= f.inputs do %>
<%= f.input :parking_company_id, :as => :select, :collection => Hash[ParkingCompany.all.map {|c| [c.company_name,c.id]}], :required => true %>
<%= f.input :branch_name, :required => true %>
<%= f.input :email, :required => true %>
<%= f.input :telephone, :required => false %>
<%= f.input :latitude, :hint =>"Automatically filled based on address" %>
<%= f.input :longitude, :hint =>"Automatically filled based on address" %>
<%= f.input :airport, :required => true %>
<%= f.input :address1 %>
<%= f.input :address2, :required => false %>
<%= f.input :address3, :required => false %>
<%= f.input :city %>
<%= f.input :county %>
<%= f.input :postcode %>
<%= f.input :country, :as => :country, :priority_countries => ["United Kingdom"], :required => true %>
<% end %>
<br />
<%= f.actions do %>
<%= f.action :submit, :button_html => {:class => 'btn-primary', :disable_with => 'Please Wait...' } %>
<%= f.action :cancel, :button_html => {:class => 'btn-danger', :disable_with => 'Please Wait...', :method => :delete } %>
<% end %>
<% end %>
<% else %>
<br />
<h1> You are not authorised to do this! <h1>
<% end %>
I have destroy action in my controller too
I have a simple form:
<%= f.input :type, :required => true, :collection => ["Nonprofit","School","Company"], :hint => "Note: nonprofits will need to provide proof of nonprofit status", :input_html => { :value => params['type'] } %>
<%= f.input :name, :label => "Organization" %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :email %>
A user gets to this page through a url like http://www.website.com/org/signup?type=Company
I can use this format to enter a value into a field like name or email, but can't figure out how to pass the param to the drop down.
I've already tried a few things including changing :value to :selected or :option but nothing seems to work.
Alright, figured it out! Posting here for future use.
<%= f.input :type, :required => true, :collection => ["Nonprofit","School","Company"], :hint => "Note: nonprofits will need to provide proof of nonprofit status", :selected => params['type'] %>
The trick is to drop the :input_html part and just use
:selected = > params['type']
Hope that helps someone in the future!
I can't get an image to show in a Formtastic form with radio buttons. Here's my form. The :activity_id, :as => radio is the issue:
<%= semantic_form_for #event do |f| %>
<%= f.inputs do %>
<%= f.input :date, :as => :string, :input_html => { :class => 'jquery-ui-date'} %>
<%= f.input :date, :as => :hidden, :input_html => { :id => 'date-alt'} %>
<%= f.input :activity_id, :as => :radio, :collection => Activity.all %>
<% end %>
<%= f.actions do %>
<%= f.action :submit, :as => :button %>
<%= f.action :cancel, :as => :link %>
<% end %>
<% end %>
That works fine as far as showing the radio button, the activity name, and saving correctly on submit. But I need to show the image that goes with the activity because most of my users cannot read and must rely on images and TTS. I've got the images showing in my other views.
I've tried dozens of combinations of things with :hint, and :wrapper_html, and image_tag and so on. So many variations I've become scrambled in the brain-pan.
A sample attempt:
<%= f.input :activity_id, :as => :radio, :collection => Activity.all, :hint => f.template.image_tag(f.object.image_url(:thumb)) %>
This gives me an "undefined method `image_url'" error. Yet this :hint works fine elsewhere.
I'll switch back to a standard html.erb view if that helps, but my problem there was a "stringify_keys" error I was unable to solve.
There's gotta be a way. Please? Thanks much. . .