So I have this form written in haml
= form_tag assign_photographers_path, class: "col-md-12 assign-photographers-form-#{portfolio.id}" do
= hidden_field_tag :portfolio_id, portfolio.id
= hidden_field_tag :user_id_1, "", class: "user_id_1"
= hidden_field_tag :user_id_2, "", class: "user_id_2"
= label_tag :user, "Begin typing to assign the first photographer:"
%br
.col-md-8.col-md-offset-2
= text_field_tag :user, nil, class: "form-control photographer-search", data_id: portfolio.id
.clearfix
%div{class: "photographer-list#{portfolio.id} col-md-6 col-md-offset-3"}
%h3 Chosen photographers
.clearfix
%br
= submit_tag "Assign Photographers", :class => "btn btn-primary"
In the source code it shows
<form accept-charset="UTF-8" action="/photographers/assign" class="col-md-12 assign-photographers-form-19" method="post"></form>
The contents of the form are then printed below the form. I have no idea why it's printing outside of the form tags. What's wrong with the code and how can I fix it?
Related
I have a recipe website made with rails and some haml on c9.io. On the show page, I'd like to display the price that the user inputted in a simple form with a dollar sign next to it. I tried using a <p> tag, however the dollar sign appears on another line.
Here is my show.html.haml file:
#post_show
%h1= #post.title
%p.username
Shared by
= #post.user.name
about
= time_ago_in_words(#post.created_at)
.clearfix
.post_image_description
= image_tag #post.image.url(:medium)
.description= simple_format(#post.description)
%h6 Notes:
.notes= simple_format(#post.notes)
%h6 Price:
%p
.price= (#post.price)
.post_data
= link_to "Visit Link", #post.link, class: "button", target: "_blank"
= link_to like_post_path(#post), method: :get, class: "data" do
%i.fa.fa-thumbs-o-up
= pluralize(#post.get_upvotes.size, "Like")
= link_to dislike_post_path(#post), method: :get, class: "data" do
%i.fa.fa-thumbs-o-down
= pluralize(#post.get_downvotes.size, "Dislike")
%p.data
%i.fa.fa-comments-o
= pluralize(#post.comments.count, "Comment")
- if #post.user == current_user
= link_to "Edit", edit_post_path(#post), class: "data"
= link_to "Delete", post_path(#post), method: :delete, data: { confirm: "Are you sure?" }, class: "data"
#random_post
%h3 Check this out
.post
.post_image
= link_to (image_tag #random_post.image.url(:small)), post_path(#random_post)
.post_content
.title
%h2= link_to #random_post.title, post_path(#random_post)
.data.clearfix
%p.username
Share by
= #random_post.user.name
%p.buttons
%span
%i.fa.fa-comments-o
= #random_post.comments.count
%span
%i.fa.fa-thumbs-o-up
= #random_post.get_likes.size
#comments
%h2.comment_count= pluralize(#post.comments.count, "Comment")
- #comments.each do |comment|
.comment
%p.username= comment.user.name
%p.content= comment.content
%h2 Share your opinion:
= render "comments/form"
And here is my posts' form.html.haml:
%div.container
= simple_form_for #post do |f|
= f.input :image
= f.input :title
= f.input :link
= f.input :description
= f.input :notes
= f.input :price
%br
= f.button :submit, class: "btn btn-info"
Help would be greatly appreciated.
EDIT:
So now, I have added the following:
%span .input-group-addon $ .price= (#post.price)
However, the dollar sign is on the top line, and the price is on the bottom.
p is block content so will cause a new line by default in html. You can either handle this with CSS or use something that is inline like a span tag
Haml input with preceding dollar sign just include in your code as you want to:
Or just use classes:
.input-group
%span.input-group-addon $
%input.form-control{:placeholder => "Price", :type => "text"}/
Looks like: http://jsfiddle.net/s6Xu6/1/
I'm attempting to a create a simple form that allows me to run a new search on the existing 'results' page using simple form.
The exact same code works fine when performing the search from another (landing) page. However, when I try to insert it into the results page I'm getting
undefined method 'vtype' for #
<Venue::ActiveRecord_Relation:0x007fd6860eb730>
vtype is both a table column and also the name of the param i'm passing to search on.
The simple_form looks like this:
<%= simple_form_for :results, html: { class: "form-inline justify-content-center" } do |f| %>
<%= f.error_notification %>
<%= f.select :vtype, options_for_select([['Happy Hours Anywhere','Anywhere'],['After Work Drinks','After Work Drinks'],['Somewhere to Relax with Friends', 'Relaxing with Friends'], ['A Club Night','Club Night'], ['Somewhere for Date Night','Date Night'], ['A Place to Watch Sports', 'Watching Sports']]),{} ,:class => "form-control select-box font-lightweight" %>
starting
<%= f.select :date, options_for_select(dates_for_search_select.each_with_index.map{|d, i| [d[1],d[0]]}), {}, :class => "form-control select-box font-lightweight" %>
at
<%= f.select :time, options_for_select(times_for_search_select.each_with_index.map{|d, i| [d[1],d[0]]}), {}, :class => "form-control select-box font-lightweight" %>
</h4>
<%= f.button :submit, 'Discover', :class => 'btn btn-block btn-danger btn-embossed top-margin ' %>
<%end%>
My controller looks like this:
def results
if params.has_key?(:results)
##results = Venue.joins(:offers).where("offers.offertype = '2-4-1'")
#finddate = (params[:results][:date]).to_date
#findtime = (params[:results][:time]).to_time
#resultsdate = DateTime.new(#finddate.year,#finddate.month,#finddate.day,#findtime.hour)
#results = Venue.joins(:offers).where(["venues.vtype = ? and offers.start >= ?", params[:results][:vtype], #resultsdate])
else
#results = Venue.joins(:offers).where(["offers.start = ?", Date.today])
end
end
What's wrong with this form running on the 'results' page?
I'm trying to get a form inside a modal. Everything after the form tag shows up, but not the actual form tag there for can't be submitted. I am using the same form in other pages and it does work except here.
AdGroups/edit.html.haml
%div(id="openModal" class="modalDialog")
%div
%a(href="#close" title="Close" class="close")
%div
= form_tag car_path, :url => {:controller => 'cars', :action => 'create'}, :html => {:multipart => true,:id =>'car-form'} do |f|
%div(class="control-group")
= label_tag "Year"
%br
= text_field_tag "year"
%br
%div(class="control-group")
= label_tag "make"
%br
%select{ :name => "make", :class => "chosen" }
- #makes.each do |m|
%option{:value => m.id}= "#{m.name}"
%br
%div(class="control-group")
= label_tag "Model"
%br
= text_field_tag "model"
%br
%div(class="control-group")
= label_tag "Trim"
%br
= text_field_tag "trim"
%br
%div(class="control-group")
= label_tag "Car Image(s)"
%br
= file_field_tag "files[]"
%br
= submit_tag
When I inspect the form rather than the form tag it has an input tag. Any idea why?
<div class="modalDialog" id="openModal">
<div>
<a class="close" href="#close" title="Close"></a>
<div></div>
<input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="fc2o2n0JJlcMISfYQACsF0mNSrVkKnoa37eF2dDrGPPIu9CnJVVaNFz3drg8dAoOf1pm>
This might take a few tries...
It looks like your form_tag might be wrong. Try:
= form_tag cars_path, multipart: true, id: 'car-form' do
Can you try doing just this (to see if you can get an empty form to render):
#openModal.modalDialog
= form_tag cars_path, multipart: true, id: 'car-form' do
foo
Make sure you're using cars_path and not car_path.
I want to have form for possible answers in poll and two submit buttons. First one passing all text fields, second one passing one of these fields as nil causing validation error. This is my _form.html.haml file:
= form_for [#poll, #question] do |f|
- if #question.errors.any?
#error_explanation
%h2= "#{pluralize(#question.errors.count, "error")} prohibited this question from being saved:"
%ul
- #question.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :title
= f.text_field :title
%p
= f.label :kind
.radio
-#kind_options.each do |option|
%label
=f.radio_button :kind, option[1]
=option[0]
=f.fields_for :possible_answers do |c|
%p
=c.text_field :title, class: "form-control", placeholder: "Enter a possible answer"
.actions
= f.submit 'Save', class: "btn btn-primary"
- x = f
= x.hidden_field :kind, :value => nil
= x.submit 'Corrupted Sumbit Button', class: "btn btn-primary"
It seems that there is no difference if I submit x or f, :kind is blank even I choose it in radio button and click on f.submit button. How to work this out?
When I submit the following form, the get URI is displaying an empty button param...which doesn't hurt anything, but looks ugly.
How can I get rid of it?
Thanks
=simple_form_for :category,
url: new_category_path,
method: :get,
class: "navbar-form navbar-left" do |f|
.input-group
=f.search_field :search,
type: "search",
class: "form-control",
placeholder: "Search for a category!"
=f.hidden_field :parent_id, :value => #category.id
%span.input-group-btn
=button_tag type:'submit', class: "btn btn-search" do
%i.fa.fa-search
the url looks like:
http://localhost:3000/categories/new?utf8=%E2%9C%93&category%5Bsearch%5D=test&category%5Bparent_id%5D=1&button=
Set :name option to nil. That should do the trick.
%span.input-group-btn
= button_tag type:'submit', class: "btn btn-search", name: nil do
%i.fa.fa-search