Add $ next to price input inputted by user - ruby-on-rails

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/

Related

Rails form_with to link_to

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();
});
});

Translation for form_tag submit button

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

How to add corrupted submit button?

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?

Devise edit form in modal, not populating fields unless it's rendered from the normal edit view

I'm trying to have Devise users be able to edit from a modal. The problem is, when the modal loads, it doesn't populate the forms with any information. But if I open the modal from /users/edit the form does populate. Anyone know how to go about this?
_edit.html.haml
.row
.small-2.large-4.columns
.small-4.large-4.columns
%h2
Edit #{resource_name.to_s.humanize}
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { :multipart => true, method: :put }) do |f|
= devise_error_messages!
%div
= f.label :email
%br/
= f.text_field :email
%div
= f.label :company_name
%br/
= f.text_field :company_name
%div
= f.label :branding
%br/
= f.file_field :branding
%div= f.submit "Update"
%h3 Cancel my account
%p
Unhappy? #{button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete}
= link_to "Back", :back
.small-6.large-4.columns
It's rendered from my application/layout like this:
#editProfile.reveal-modal{"data-reveal" => ""}
= render "devise/registrations/edit"
%a.close-reveal-modal ×

Using remote true with a different view

I have a structure that looks like this :
modifications
_form
_miniform
index
My index shows something like :
%span.right
= render "modifications/form", modification: modification
Form and Miniform are almost identical:
.modification-forms
- if can? :reject, modification.model
= form_tag modification_rejections_url, class: "inline", remote: true do |f|
= hidden_field_tag :id, modification.model.id
= submit_button "Reject", class: 'btn btn-danger'
- if can? :approve, modification.model
= form_tag modification_approvals_url, class: "inline", remote: true do |f|
= hidden_field_tag :id, modification.model.id
= submit_button "Approve" , class: 'btn btn-success'
vs miniform
.modification-device-forms
- if can? :reject, modification.model
= form_tag modification_rejections_url, class: "inline", remote: true do |f|
= hidden_field_tag :id, modification.model.id
= submit_button "<i class='icon-remove'> </i>".html_safe
- if can? :approve, modification.model
= form_tag modification_approvals_url, class: "inline", remote: true do |f|
= hidden_field_tag :id, modification.model.id
= submit_button "<i class='icon-ok'> </i>".html_safe
When i render the _form partial, ajax performs how you would expect. After clicking a button, the row disappears.
However, when I swap in miniform, it no longer works. The ajax runs, but it doesn't delete the row.
I assume this is rails conventions getting mixed up, but im not so good with rails magic, and have no idea where to start in deciphering this.
Is there a way to make this work?

Resources