Would you know how to make a pull down or drop down menu for a form text field?
Currently, the user needs to to type in text "Rating" then submit the form. But ideally, they should select a rating of "Awesome" "Good" or "Meh" from a pull down, rather than be able to enter a custom text. Any advice in the right direction would be appreciated.
Thank you.
_form.html.erb
<%= simple_form_for(#post) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :Duration, required: true, autofocus: true %>
<%= f.input :Rating %>
</div>
<div class="form-actions">
<%= f.button :submit, "Log it!" %>
</div>
<% end %>
Please try to replace the line:
<%= f.input :Rating %>
with:
<%= f.select :Rating, options_for_select(["Awesome", "Good", "Meh"]) %>
Related
I was looking at the question below, which has a good answer for what I will ask, but I have a doubt. I cannot comment yet so that is why I am making another post.
How to submit multiple, duplicate forms from same page in Rails - preferably with one button
This is my view for the form
new.html.erb
<h1 class="page-title">Nuevo Precio</h1>
<hr class="title-division">
<div class="alta-form-container">
<%= form_tag "/precios" do %>
<% 2.times do %>
<%= render 'form', precio: #precio %>
<% end %>
<%= submit_tag "Submit", class: "btn btn-success" %>
<% end %>
<%= link_to 'Lista Precios Cliente', client_precios_path %> <br><%= link_to 'Ver', [#client, #precio] %> <br>
</div>
and my _form.html.erb
<div class="field">
<%= label_tag :precio, "Precio" %>
<%= text_field_tag "precios[][precio]" %>
</div>
<div class="field">
<%= text_field_tag "precios[][cant_acomodato]" %>
</div>
<div class="field">
<%= hidden_field_tag "precios[][client_id]" %>
</div>
When I submit the form I get an error that says
'No route matches [POST] "/precios"'
which I'm guessing is because on my new.html.erb I wrote form_tag "/precios" do
Any thoughts on what I should change or edit? thanks in advance
actually you have only one form here, because _form.html.erb will generate only inputs, that according to form below
<%= form_tag "/precios" do %>
that will generate
form action="/precios" method="post">
if you want leave it like that, you should add to your config/routes.rb
post '/precios', to: 'controller_name#method_name', as: :controller_name_method_name
your situation:
post '/precios', to: 'PreciosController#create', as: :precios_create
also check this
documentation
So I'm following a tutorial for RoR but I can't seem to get the alignment right.If I copy and paste the code for the tutorial, it will look like
this
Here is the code:
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(#user) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.email_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
But if I put col-md-1, then it sort of works, looking like this
Is it possible to still use col-md-6 but have it properly aligned like the second photo? I don't know what else to change other than the numbers.
I am not able to test this right now but you may be able to change your first line of your form to:
<%= form_for #user, :html => {:class => "form-horizontal"} do |f| %>
This should add the html and css need to make the form horizontal:
<form class="form-horizontal">
Some what like this example: https://jsfiddle.net/obp9x1yr/7/
This might be a good post to read for more information: Rails Bootstrap how to format form_for (width grid collapses)
I am trying to create a form that accepts HTML. So that when I type <br> or use divs it understands and populated my content block accordingly. Can anyone point me in the right direction for this?
Here's the form I am using if that helps:
<%= simple_form_for(#daily) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :title %>
<%= f.input :content %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
Replace <%= f.input :content %> with <%= f.text_area :content %>. That doesn't do much but make a multi-line input area (looks better). However, when you display the data on your webpage (i.e. after you submit the form), you can put something like this:
<p>#daily.content.html_safe</p>
I used to roll my own authentication following Hartl's tutorial, but now that I need more advanced features such as password retrieval or email confirmation, I moved on to the Devise gem. However, I'm having some hard time navigating around what is already provided by devise. I'm doing some research in order to better understand it.
Meanwhile, I'm having problems with styling the sign in and sign up forms. For the sign up form, it looks fine at first, but the spacing becomes weird once I submit an invalid form.
For the sign in form, I cannot seem to figure out how to put the checkbox and the label on the same line. I tried all different kinds of divs and inline block. Please help me out. Thanks!
/devise/registrations/new.html.erb
<div class="center">
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= field_set_tag "Name" do %>
<%= f.text_field :first_name, placeholder: "First Name*", autofocus: true %><br>
<%= f.text_field :middle_name, placeholder: "Middle Name" %><br>
<%= f.text_field :last_name, placeholder: "Last Name*" %><br>
<% end %>
<%= field_set_tag "Account" do %>
<%= f.email_field :email, placeholder: "Email*" %><br>
<%= f.password_field :password, placeholder: "Password*" %><br>
<%= f.password_field :password_confirmation, placeholder: "Password Confirmation*" %>
<% end %>
<div><%= f.submit "Sign up", class: "btn btn-large btn-primary" %></div>
<% end %>
Already a user? <%= render "devise/shared/links" %>
</div>
/devise/sessions/new.html.erb
<div class="center">
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= f.email_field :email, placeholder: "Email", autofocus: true %><br>
<%= f.password_field :password, placeholder: "Password" %><br>
<div class="row">
<% if devise_mapping.rememberable? %>
<div>
<div class="remember-me">
<div><%= f.label :remember_me %></div>
<div><%= f.check_box :remember_me %></div>
</div>
</div>
<% end -%>
<%= f.submit "Sign in", class: "btn btn-primary" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
</div>
Check this stackoverflow link you will find the solution for the sign in page issue.
For the sign up page you are getting the spacing issue when input are not correct because your form is not showing the error messeges properly check out this image you will understand.
Disclaimer: I'm still very new to web development in general, so I'm sorry if this is a terrible question.
Why is everything in HTML evaluated on a line-by-line basis? I've noticed that any code (scripts?) that I throw into HTML requires me to cast it to its language on every single line like so:
<div class = "row">
<div class = "span6 offset3">
<%= form_for(#user) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.text_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.text_field :password_confirmation %>
<%= f.submit "Create My Account", :class => "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
But why can't it evaluate the scripts like this:
<div class = "row">
<div class = "span6 offset3">
<%= form_for(#user) do |f|
f.label :name
f.text_field :name
f.label :email
f.text_field :email
f.label :password
f.text_field :password
f.label :password_confirmation, "Confirmation"
f.text_field :password_confirmation
f.submit "Create My Account", :class => "btn btn-large btn-primary"
end %>
</div>
</div>
Would it not make developing so much simpler to allow for this? To me, this just makes so much more sense, but its not done this way, probably for a good reason. If I'm writing out a fair bit of code (Ruby in this case), I am not a huge fan of casting every line at the start and finish.
I get that I'm having the HTML evaluate each line as an HTML object by casting it, but is it not possible to just have it assume that every line (or some other syntax - maybe actually use semi-colons) is a new piece of script to evaluate?
I guess what I'm asking is why are blocks of code evaluated this way and why hasn't it been made more efficient?
You can, but you have to do everything that the <%= %> tag does.
I'm not sure about the syntax in Ruby, but basically a tag like this:
<%= f.label :name %>
does output to the page, i.e. a shortcut for:
<% response.write(f.label :name) %>
So, you could do it it within a single script tag, if you add the commands for doing the output:
<%= form_for(#user) do |f|
response.write(f.label :name)
response.write(f.text_field :name)
et.c...