haml

How to do an if/else in HAML without repeating indented code

∥☆過路亽.° 提交于 2019-12-12 07:43:51
问题 Depending on if a user is signed in or not, I'd like to print a different kind of %body-tag. This is how I currently do it: - if defined? @user %body(data-account="#{@user.account}") %h1 Welcome -# all my content - else %body %h1 Welcome -# all my content As you can see there's a lot of duplicated code in there. How can I eliminate this? I already tried the following: - if defined? @user %body(data-account="#{@user.account}") - else %body %h1 Welcome -# all my content Unfortunately, this

Unescaping inline links in haml

萝らか妹 提交于 2019-12-12 05:43:22
问题 So I'm trying to get a remove link next to the caption in an emails form. However, my rails voodoo is clearly very weak. It escapes the HTML and I can't figure out how to get it to not. Any hints? = f.input :email, :label => "Email " + link_to_remove_fields("[x]", f) [edit] oh and yes, this does the same thing: = f.input :email, :label => "Email #{link_to_remove_fields("[x]", f)}" and here's my helper method... def link_to_add_fields(name, f, association) new_object = f.object.class.reflect

Ruby on Rails page does not refresh when form is posted

梦想与她 提交于 2019-12-12 04:47:25
问题 In the code sample posted below, I am trying to allow the user of the page to filter out which projects should be displayed by user. I am able to successfully filter the results by manually modifying the parameters passed in the address bar. But when I click the Filter button on the page it does nothing at all. It should refresh the page with the new parameters being passed when the button is pressed. Any ideas as to why this happens? Do I need to add anything in my controller? View: = form

can't convert true into String

夙愿已清 提交于 2019-12-12 04:29:07
问题 I'm having some problem with what I think is my cache. I'm getting this error message: ListsUsersController# (ActionView::Template::Error) "can't convert true into String" Here is the code: %footer - cache "footer-movies-#{Time.now.hour.to_s}", expires_in: 2.days do .foot-movies %ul - Movie.footer.each do |movie| %li= link_to (image_tag movie.poster, size: "60x92"), movie_path(movie), title: movie.title It's complaining about line 40, which is the line containing .foot-movies . The code works

Using colon syntax and variables in Sass

馋奶兔 提交于 2019-12-12 03:49:17
问题 I am still using the old colon syntax (I prefer it more than the bracket syntax) and this particular code: a.button-link +box($main-color) +border-radius(5px) :background :color $main-color :color #fff :padding 5px generates a warning like so: DEPRECATION WARNING: On line 12, character 3 of '/Users/eumir/rails_apps/dxconnect/app/ stylesheets/partials/utilities/_link-styles.sass' Setting properties with = has been deprecated and will be removed in version 3.2. Use "background: $main-color"

Display all the values for every date in JSON

让人想犯罪 __ 提交于 2019-12-12 03:21:49
问题 I have the following JSON: { "groups" : [ { "values": "21", "date": "2013-02-22" }, { "values": "25", "date": "2013-02-22" }, { "values": "20", "date": "2013-02-22" }, { "values": "19", "date": "2013-02-22" }, { "values": "42", "date": "2013-02-10" }, { "values": "30", "date": "2013-02-10" }, { "values": "11", "date": "2013-02-10" } ] } I have the values and the date already extracted in a Ruby Class. I want to find the "highest" and "lowest" value for every date. How do I do that? Also I

Set attributes in haml using variable in mustache

家住魔仙堡 提交于 2019-12-12 03:15:55
问题 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? 回答1: You could use :plain , something like this: :plain <div class="module-subtitle" title="{{title}}"> {{title}} </div> 回答2: Without seeing more of your code and running some

How to extract values from a custom SQL query

我是研究僧i 提交于 2019-12-12 03:14:14
问题 I have the following custom query whereby I am trying to extract the values so they are meaningful for my app @sizes = Product .joins(:product_properties) .joins('INNER JOIN variant_properties on product_properties.property_id = variant_properties.property_id') .joins('INNER JOIN properties ON properties.id = product_properties.property_id AND properties.id = variant_properties.property_id AND properties.display_name = \'Size\'') .joins('INNER JOIN variants on variants.product_id = products

inject html using ajax

点点圈 提交于 2019-12-12 02:38:01
问题 I have a HAML page with some div elements. I need to inject this into a div on another page when a button is clicked. how do i do this? thanks 回答1: You have to add the jQuery plugin from jQuery.com. you can download the plugin or use the link http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js as src in the js file. then use the follwing code $(document).ready(function(){ $("#your_button_Id").click(function(){ $.ajax({ url: "test.html", context: document.body, success: function(response

How can I set a session variable from a js inside haml in ruby on rails?

◇◆丶佛笑我妖孽 提交于 2019-12-12 02:28:58
问题 I have table row shading (for groups of row) via js. I want to make it so that the shading is remembered through a session variable. The haml partial I am using has: Group Shading: %a{:href => '#', :id => 'row_colors_on'} On %a{:href => '#', :id => 'row_colors_off'} Off the js has: $(function(){ $("a#row_colors_on").click(function(){ $(".row_color_group_1").addClass("color_group_1"); $(".row_color_group_2").addClass("color_group_2"); $(".row_color_group_3").addClass("color_group_3"); <%-