I have a form_with like this:
= form_with model: product.product_posts.new do |f|
= hidden_field_tag :container, '#related-products-list'
= f.hidden_field :product_id
= f.hidden_field :post_id, value: #post.id
= f.submit "+", class: "btn btn-info m-btn m-btn--icon m-btn--icon-only m-btn--pill add-action-button"
How to get the same with a link_to to get full div clickable instead of the "+" button?
=link_to {SOLUTION} do
.mydiv
You can use Javascript to achieve this. If you use jquery,
$(document).ready(function() {
$('.mydiv').click(function () {
$('#form_id').submit();
});
});
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?
In Rails, when you have a form like this:
<% form_for #post do |f| %>
<%= f.submit %>
<% end %>
You can have a specific translation like this for when the button is clicked:
en:
helpers:
submit:
create: "Create a {{model}}"
update: "Confirm changes to {{model}}"
But I have a form_tag, which submits a GET to an index path to set a filter:
= form_tag admin_dashboard_index_path, method: :get, class: "table_filter" do
= select_tag :company, options_for_select(#filter_companies.map{ |c| [c.name, c.id] }, params[:company]), include_blank: true, class: "selected"
= submit_tag :submit, value: I18n.t('.general.filter'), class: 'btn'
How can I get a specific translation for this situation?
Add this to the method so that the button label stays the same after pressing it.
= submit_tag :submit, value: t('.general.filter'), class: 'btn', data: { disable_with: t('.general.filter') }
submit_tag method
I try to add multipart upload for Carrierwave in my form, but I have two controllers(admin_posts and posts) in one model(post).So I do not understand how to specify this
_form.html.haml
= form_for [:admin, #post] do |f|
= f.fields_for :photos do |photo_fields|
= photo_fields.file_field :image
= f.text_field :title, class: "form-control", placeholder: "Title"
= f.text_area :body, rows: 12, class: "form-control", placeholder: "Body"
.pull-right
= f.submit "Send", class: "btn btn-success"
how fix?
sorry for my English
Try this
= form_for [:admin, #post], url: your_action_path(#post), html: { multipart: true } do |f|
This is what I want:
class = "navbar-toggle" data-toggle = "collapse" data-target = ".navMenuCollapse"
This is what I got:
class="\"navbar-toggle\" data-toggle = \"collapse\" data-target = \".navMenuCollapse\""
This is what I tried:
<%= link_to 'test', welcome_index_path, {:class => '\"navbar-toggle\" data-toggle = \"collapse\" data-target = \".navMenuCollapse\"'} %>
Is there any opportunity to get quotes in the class-tag ?
Thanks for help.
Try the below code:
<%= link_to 'test', welcome_index_path, class: 'navbar-toggle', data: {toggle: 'collapse', target: '.navMenuCollapse'} %>
This should work:
<%= link_to 'test', welcome_index_path, :class => 'navbar-toggle', :'data-toggle' => 'collapse', :'data-target' => '.navMenuCollapse' %>