FAQ Database Discussion Community


How do I properly format interpolated ruby objects as jquery selectors in rails, using haml?

javascript,jquery,ruby-on-rails,ruby,haml
<% if @discussion_category %> $("#<%= dom_id(@discussion_category) %>_notice").html(''); $("#<%= dom_id(@discussion_category) %>").html("<%=escape_javascript(render(partial: 'display_change', locals: {discussion_category: @discussion_category}))%>"); $('#discussion_category_links').show(); <% end %> I did the following, but I'm doing something wrong: -if @discussion_category javascript: $(escape_javascript(#{dom_id(@discussion_category)} + '_notice').html('');...

Rails - putting elements inside Div from view rendered using helper in HAML

ruby-on-rails,views,haml,render
I have two views that creates functioning modal. Top one is made with helper method .modal-header %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} &times; %h3.modal-title = title .modal-body (some necessary code) And after that there is the second file with content of that modal that looks like this:...

Varying form-control styles on the same page Bootstrap CSS

css,ruby-on-rails,forms,bootstrap,haml
Is there a way to make the placeholder text in a form white in one section and gray in another section? HAML: Signup form 1: = form_tag splash_signup_path, role: :form, :class=>'form-horizontal', :remote=>true do .col-sm-12 .input-group = text_field_tag :signup_email, '', :class=>'form-control', :placeholder=>'Enter your email address to receive the lastest updates' %span.input-group-btn...

Haml and JavaScript and Ruby communication

javascript,ruby-on-rails,ruby,haml
I have some code, like this: %div{:id=>"alerts_tab",:class=>"settings_tab"} %div{:class=>"main_block"} %div{:class=>"left_block"} %p Select 1 = radio_button_tag 'gender', 'male', :id=>"daily_frequency" Daily = radio_button_tag 'gender', 'male', :id=>"weekly_frequency" Weekly = radio_button_tag 'gender', 'male', :id=>"monthly_frequency" Monthly %p Try it %input{:name => "malfunction_affects_more", :type => "checkbox", :class => "check_box", :value=>"off"} AAAAAAAAAAAAAAAAAAA...

List of checkboxes in HTML.haml

html,css,ruby-on-rails,ruby-on-rails-4,haml
I've been working on an application in ruby on rails and trying to display list of check boxes like this [ ] Conflict Resolutions [ ] Customer Know how [ ] personal Branding But I managed to get this Conflict Resolution [ ] Customer Know How [ ] Personal Branding...

haml/RoR: How to make a substring of a rails label have %i applied to it

ruby-on-rails,haml
I am trying to apply an html tag to a substring of a rails form_for label, in the following context. =f.label :question_7, "The Portrait of a Lady _ Henry James, an American author." When I would like to do the following "<i> The Portrait of a Lady </i> _ Henry...

What is the difference between = and - in haml while writing ruby code?

ruby-on-rails,ruby,haml
So I am a newbie at HAML. While going through the HAML tutorial the way to represent ruby code was mentioned as = eg: %strong= item.title but when I ran this code: = @list.documents.each do |doc| %tbody %tr %td= doc.display_name along with all the list data which was displayed there...

Ruby haml unexpected ending error

ruby-on-rails,ruby,haml,simple-form
= simple_form_for @pin, html: { multipart: true} do |f| - if @pin.errors.any? #errors %h2 = pluralize(@pin.errors.count, "errors") prevented this Pin from saving %ul - @pin.errors.full_messages.each do |msg| %li= msg .form-group = f.input :title, input_html: { class: 'form-control' } .form-group = f.input :description, input_html:{ class: 'form-control' } = f.button :submit, class:...

Raty.js not loading once infinite scroll occurs in Rails

javascript,ruby-on-rails,haml,infinite-scroll,raty
I'm using the infinite scroll option from Masonry-rails and am implementing a rating system via Raty.js. When the first few pins show up, the average rating is shown, however, after infinite scroll, the new pins do not have average ratings. Attached is my index.html.haml. How do I allow raty.js to...

Cannot get filter to execute in AngularJS

javascript,angularjs,date,haml,angular-filters
I have an ng-repeat of events, each of which has a date. I want to allow the user to filter out all events not between two dates. I figured I'd make a custom filter for this. I'm using HAML, so here's how my HTML looks: %tr{'ng-repeat' => 'event in events...

jQuery Tablesorter File Size in Rails App

javascript,jquery,ruby-on-rails,haml,tablesorter
So all of my columns sort without issue, except for my Media column which displays quotas for file size limits (GB, TB, etc.) I suspect the Rails NumberHelper number_to_human_size isn't playing nicely with tablesorter. Anyone have an idea how to get it to sort, while utilizing the NumberHelper? _table.html.haml %table#myTable.tablesorter...

Where is my partial name getting cached?

ruby-on-rails-4,haml,partials
I am trying to do some refactoring but am not able to move my partial without getting a missing template error from the calling template. I renamed and moved the partial, then in the calling template, I changed from: = render 'slot_fields', f: builder To: = render 'slots/slot_create_fields', f: builder...

ReNesting Resource Routes in Rails

ruby-on-rails,routing,haml,member,nested-resources
So I just made one of my objects a nested resource of my user object. Now all of my links don't work and my index won't show. I am getting the error: /views/photos/index.html.haml where line #8 raised: No route matches {:action=>"show", :controller=>"photos", :id=>nil, :user_id=>nil} missing required keys: [:id, :user_id] with...

Select with different values in haml

ruby-on-rails,ruby,haml
I'm trying to create a select box using jQuery's select2 with a list of options but with different values. Right now, the values are equal with what is being displayed. For example, the option should say "Runner" while the value for that option should say "Runner - Individual". I cannot...

How to use link_to_if with HAML

ruby-on-rails-3,haml,view-helpers
I'm trying to figure out how to write in HAML the use of link_to_if helper with a do block. I tried this one but it generate an error : = link_to_if(test, my_text, my_path) do - some_other_text Error : syntax error, unexpected ';', expecting ')' end;_hamlout.buffer << _hamlout.f... I know I...

Rendering a dynamically generated background based on width

html,css,ruby-on-rails,sass,haml
So I have a background image attribute (as a string referencing an image in the project), that belongs to a Badge table. I'm rendering each background image based on the current path. But I want to render different images at two different max-widths. For example, .badge-headline-background{style: "background-image:url(../assets/header-graphics/#{@badge.background})"} renders a background...

Determining the correct usage of named yield with content_for

ruby-on-rails,ruby-on-rails-4,haml
I have a lot of shared code for several different forms, and am trying to use a named yield. I want _nav.html.haml to render the form with the field for each page defined in a content_for block. Example view: - content_for :form_fields do = f.text_field :name = f.text_field :number =...

rails haml if add class

ruby-on-rails,if-statement,haml
How can I write this code in haml without repeating the render line? - if i % 2 == 0 %section.wrapper-md.list = render partial: 'property' - else %section.wrapper-md.list.background-gray = render partial: 'property' Thanks!!...

Create and remove div in jQuery and Rails

javascript,jquery,ruby-on-rails,haml
In my website I have different boxes of different artists and a play button on each to load a Spotify player. I am using to do that this: $(document).ready(function(){$(".playid-"+#{artist.id.to_s}).click(function () { $(".player-id-"+#{artist.id.to_s}).fadeToggle() ;} Is working fine. However when I click to the second/third... play button the div of the player...

Text box and check box dependency in haml

javascript,jquery,ruby-on-rails,haml
I have a form in htaml.haml (ruby on rails) that consists of a list of check boxes and two text boxes. These two text boxes are dependent on two check boxes. If a check box is clicked , corresponding text box should be editable, otherwise it should be non-editable. My...

How to incorporate Cocoon links into buttons

html,ruby-on-rails,haml,cocoon-gem
In a rails project I am using the cocoon gem to create a nested form. In the provided example, the method link_to_remove_association is used, generating a link which deletes the current nested form when clicked. This works fine as a link, but I wish to have the same functionality in...

Rails: get arguments passed to partial

ruby-on-rails,haml
Is it possible to get the arguments passed to a partial from within the that partial? # in some_view.html.haml = render 'foo_partial', some: "stuff", goes: "here" # in foo_partial.html.haml = arguments = ??? # im trying to get this to contain {some: "stuff", goes: "here"} NOTE To clarify, I wanted...

Embedding ruby into HAML without flanking/preceding 'tags'

haml
My ruby code shows up (and renders as 'Hello World', which is what's in the database), when I type: %p= @task.notes But when I try it this way rails breaks (NoMethodError in Tasks#index): %p= Some text before code @task.notes When I try this it just shows me literally what I...

add links into haml template

html,css,haml
I implemented a template named "_list_two_lines" %ul{:style=>"padding-top: 0; margin-top: 0"} - content.each do |element| %li{:style=>"font-family: Roboto, sans-serif; color: #333;font-weight: 300; font-size: 14px; "} &#10003; = render :partial => _text, :locals => {:inline =>true, :content => element[0] , :weight => bold_weight_email} %br = render :partial => _text, :locals => {:inline =>true,...

HAML =form.submit add a class with t() stopping it

javascript,html,haml
I need to add a class of btn and btn-primary to: = f.submit t('.save', default: t('helpers.links.save')) - if question_set.shared? So that it matches the rest of my page. But no matter what I do it does not put those classes in. I have tried: = f.submit, :class => "form_submit" Placed...

How to write the content of external .js files in a js.haml file (Ruby on Rails)

javascript,ruby-on-rails,view,haml,external
I'm using Ruby on Rails framework and I love it. Until now I was using the show.html.haml for my views and everything worked fine. We wanted to add another option of supporting a GET request which consists the post-fix .js. For this purpose we added to the controller another parallel...

Long 'if' conditional in HAML

haml
So I have a very long conditional in HAML that looks like: - if condition_1 && condition_2 && condition_3 ... Now, imagine that the line is longer than 100 tabs. What's the correct way of breaking that in a multiline? EDIT: At some point I thought that something like: -...

Responsive CSS only working in mobile view, refusing to hide in normal view

css,mobile,responsive-design,haml
I've created two different footers for a page, given them two different ID's, and then written CSS so that one footer is hidden and the other shown for regular browsing, and then the opposite for mobile browsing. You know the drill. @media (max-width: $screen-lg) { #main-footer { display: block; }...

HAML - showing “|”

ruby-on-rails,haml
Very quick question concerning HAML. I'm trying to get a pipe "|" to show on my page but HAML seems to be ignoring it... In .erb I would have written something like this: <h3>Account | <%= link_to "Log in", new_user_session_path, class: "nav" %></h3> <% end %> In order to show:...

Is it posible to combine inside Symfony 2.3.* twig with haml?

symfony2,twig,haml
I wonder if theres a workaround to use twig combined with haml for symfony2 views. This is Haml http://haml.info/ (This is for Ruby On Rails) Basically is to use this: %section.container %h1= post.title %h2= post.subtitle .content = post.content instead of this: <section class=”container”> <h1><%= post.title %></h1> <h2><%= post.subtitle %></h2> <div...

Rails 4:Simple-form checkbox for active and inactive post

ruby-on-rails,ruby-on-rails-4,checkbox,haml,simple-form
Have created a check box -Boolean function in Simple-form, wanted to know how the controller can hide the post when indicative from index. When a user creates a post he has an option to hide the post from all the post list (index.html.haml). In the form i have created active...

Link works fine in rails view, but not in email [duplicate]

ruby-on-rails,ruby,ruby-on-rails-4,haml,actionmailer
This question already has an answer here: Rails 3.2 `link_to` (in email) with `method: :put` still producing GET request 2 answers I am using Rails and ActionMailer to send emails = link_to "Change", update_url( id: @model.id, value1: "data1", :value2 => "data2"), :action => 'update', :method => :put The above...

haml to html conversion for ruby on Rails application?

html,ruby-on-rails,ruby,haml
I want to do Search Engine Optimization most effectively? the following HAML meta-tags are in my new ruby on rails application.is there any advantage if i convert this into HTML ? - content_for :title, @service ? @service.page_title : " - Legal Compliance" - content_for :description, @service ? @service.meta_description : "Legal...

CSS Background Image not showing up CSS HAML

css,ruby-on-rails-4,background-image,haml
I have a background image url in a stylesheet that I'm trying to render for the header in my index page. The image is located in the assets/images folder. I tried putting in vendor/assets/images and it's not rendering from there either. views/splash/index.html.haml: %section.row.header-bg .row .col-md-6.col-md-offset-1 assets/stylesheets/splash.css.scss: .header-bg{ background-image: url('bg.png'); }...

tag in HAML

html,css,haml
How do I create a I-tag in haml? Example: <i class="fa fa-search"></i> ...

How can I change the number of items that end up in a list

ruby-on-rails,haml
I'm hacking away at a rails project and I wanted to modify the number of items that end up on a particular page. The page gets populated via an array of items. For the life of me I can't figure out how to make it show only 2 instead of...

link_to delete, deleting wrong record

ruby-on-rails,rest,iteration,haml,link-to
I'm having the strangest problem! In my RoR app, I have an .each loop. Each iteration has a link_to "Delete" for that specific iteration: - @evints.each do |e| .inteventimg = link_to e.event.name, e.event = e.id %br - if e.event.images.exists? = image_tag(e.event.images.find_by(:prime => true).location.full.url) %br - if current_user = link_to "Delete...

If clause in haml using variable from mustache

ruby,haml,mustache
Similar to this question, I want to use if clause in haml file, specifically only display the image when there is actually image url. The code is %div{ :class => "attachment {{ attachment_type }}" } %a{ :href => "{{ attachment_url }}", :target=> "_blank"} %img.image{ :src => "{{ attachment_pic_url } and...

Rails for nested array hidden input field in form (Haml)

ruby-on-rails,haml
What would be a better "Rails way" of doing it - shops.map(&:id).each do |id| <input id="p_shop_ids_#{id}" name="p[shop_ids][]" type="hidden" value="#{id}" /> I recently read that in Haml is in this sense downwards compatible. But it feels like it should be done with the rails checkbox helper instead...

Rails: Override application.css

css,ruby-on-rails,ruby-on-rails-4,haml
I'm trying to override my application.css with other css, included in header. I want to customize my application.css by this way. My header = stylesheet_link_tag 'application', media: 'all' = stylesheet_link_tag 'customized_css', media: 'all' Actual application.css.scss is overriding my tour.css.scss even its is loading before any other css Edit The order...

Bind '.error' class to manually created haml wrapper

ruby-on-rails,haml,simple-form-for
I have next group of controls: .control-group.string.required.user_name = f.input_field :name, required: true, class: 'form-control' = f.label 'User Name' = f.error :name Is there any way to bind '.control-group' to it's child input, so if input is invalid, wrapper will get class ".error" added? Thanks...

how to add a class to a conditional in HAML

ruby,haml
Ok, I have this line in my file which is in HAML - unless @place.blank? I need to add a class to it ... regardless of the condition ... I've tried doing this: - {:class => ("extra_middle" unless place.blank?)} That doesn't work. I've tried other variations to no avail. EDIT...

Haml nested blocks

html,ruby-on-rails,haml
I am newbie in HAML. So what about this in HAML ? -if @link.is_active %a -else #custom-div .custom-class So I want to see if some condition is true <a><div id = "custom-div"><div class = "custom-class"></div></div></a> And if it's false: <div id = "custom-div"><div class = "custom-class"></div></div> Without copying of blocks,...

Ruby on rails and HAML - Print a hash with background color

ruby-on-rails,haml
I have a Hash. my_hash = { "name": "aaa", "age":"28 [previous value: 27]"} I found the difference between two hashes and stored it in the above format. Now I need to print the Hash like this: name aaa age 28 [previous value: 27] But I want the background of the...

How to make a sentence inside a haml file bold?

html,ruby-on-rails,haml
Here's the code in my haml file: = render :partial => _paragraph, :locals => {:content => "It is hot. But something's definitely up."} How can I make the last sentence bold? ...

Conditional CSS in Ruby and Haml Table

css,ruby,haml
I have a list of items in a table. Some are true and some are false. Is there a way that the true elements can have one background colour whilst the false elements have another. I was considering writing a method in the application helper but I am not sure...

How to stop outputing my own html source?

ruby-on-rails,devise,haml
This may be the werdeist bug I've ever met. I'm currently building a app for personal use on Ruby on Rails, and it's still a long way from done. The main layout is as follows: !!! %html.uk-height-1-1 %head = render 'layouts/head' %body.uk-height-1-1.uk-width-1-1 = if user_signed_in? .alerts = render 'layouts/alerts' .navbar...

Haml - get current week start and end date

ruby-on-rails,ruby,haml
I'm new into HAML, and I have ( I hope easy ) question regarding date/ time. Is it possible to get start and end date of current week in HAML in not very very commplicated way? I want to use those dates for navigation in my calendar. For month and...

Apply conditional class in a rails view inside map{} using haml

css,ruby-on-rails,haml
I am trying to apply a class conditionally to the names associated with a reminder. If there are three persons associated with a reminder - Jay, Jonah and Jamison... and Jonah is the one who acknowledged the reminder, then I want his name to have the class "acknowledge", though I...

How to get rid of col-md-* padding when nested in another row, without affecting the entire grid?

html,css,twitter-bootstrap-3,haml
I got to modify a page written using HAML+SASS+BOOTSTRAP. The HAML file looks like this: .row .col-md-6 .panel.panel-default.panel-dashboard .row .col-md-6 .panel-heading Title 1 .panel-body Content 1 .panel-bottom Link 1 .col-md-6 .panel-heading Title 2 .panel-body Content 2 .panel-bottom Link 2 .col-md-6 .panel.panel-default.panel-dashboard .row .col-md-6 .panel-heading Title 3 .panel-body Content 3 .panel_bottom...

something's wrong with the css path in my haml file

css,ruby,path,sinatra,haml
The directory structure is as follows: approot ` public ` css - main.css ` views - home.haml - index.haml - main.rb and I've tried to call my css in the haml file with: %link{:rel => "stylesheet", :href => url('css/main.css')}, %link(rel="stylesheet" href="css/main.css") and %link{:rel => "stylesheet", :href => "css/main.css"} Nothing works...

Switching Between Pages Using Navbar Is 'jumpy'

jquery,twitter-bootstrap,haml,middleman
Im having a problem with the 'jumpyness' of the switching between pages when using middleman. To see what i mean see the Live Demo The problem is when i switch between pages there is a flash of another page that appears to be some kind of bullet point list. Does...

Set attributes in haml using variable in mustache

ruby,haml,mustache
I'm using both haml and mustache for frontend. There is a code snippet: .module-subtitle {{title}} I want to show a tooltip for .module-subtitle with title attribute, using the content inside {{title}}. I tried .module-subtitle{ :"title" => {{title}}} {{title}} but it didn't work as it has syntax error. Any hints?...

Can't convert html.erb's to haml with the “erb2haml” gem on Windows

ruby-on-rails,ruby,ruby-on-rails-4,rubygems,haml
Solved. Look at my answer below. My Problem: I just can't convert all my html.erb's to haml. I tried the erb2haml gem with the "rake haml:replace_erbs" command but it doesn't work. Here is the full error:       C:\xampp\htdocs\Ruby>rake haml:replace_erbs --trace ** Invoke haml:replace_erbs (first_time) ** Execute haml:replace_erbs rake...

Trouble passing Rails Data into a JavaScript Function on mouse over..? Failed attempt:

javascript,jquery,ruby-on-rails,haml
I want to pass data in rails to a javascript function. The end goal is to display this data at a specific ID Here is my current broken attempt: - if @scopes_in_common.any? .compare-box - @scopes_in_common[0..2].each_with_index do |scope, index| - v_score = instance_variable_get("@#{snake_case(scope.name)}_comparison").v_score.gsub("%", "").to_i - (index+1).odd? ? direction = "left" :...