haml

How to access instance variables in CoffeeScript engine inside a Slim template

匆匆过客 提交于 2019-12-17 08:23:10
问题 I have a Rails controller in which I am setting a instance variable - @user_name = "Some Username" In my .slim template I am using coffee engine to generate javascript and want to print out the user name from client-sie javascript code - coffee: $(document).ready -> name = "#{@user_name}" alert name But this is the javascript that is being generated?? $(document).ready(function() { var name; name = "" + this.my_name; alert(name); } How do I access controller instance variables in my

网络号 IP地址 子网掩码如何计算

只谈情不闲聊 提交于 2019-12-14 12:07:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1.Internet上每一台计算机都有唯一的地址来标识它的身份,即IP地址,使用域名其实也是要转化为IP地址的。 2.IP地址分类: A类:000~127,默认子网掩码:255.0.0.0 B类:128~191,默认子网掩码:255.255.0.0 C类:192~223,默认子网掩码:255.255.255.0 D类:224~239 E类:240~255 3.假设现有一IP地址180.210.242.131,即10110100.11010010.11110010.10000011 同时指定子网掩码为255.255.248.0 即11111111.11111111.11111000.00000000,则 网络号:两者进行与运算,即10110100.11010010.11110000.00000000(180.210.240.0) 主机号:子网掩码取反再和IP做与运算,即00000000.00000000.00000010.10000011(0.0.2.131) 子网号:这个IP本来是B类地址,默认的子网掩码是255.255.0.0,所以本来的网络号是16位,但它实际网络号是21位,就是借了5位网络位,所以可以划分2^5个子网,即32个,实际使用30个,这个网段可以容纳主机2^11个,即2048个

Can't select link_to tag as jquery selector Rails

霸气de小男生 提交于 2019-12-14 03:36:11
问题 I am a beginner rails dev. I got this link_to tag with the class of "comments_link" %h2= link_to pluralize(@recipe.comments.count, "Comment"), "#", class: "comments_link , btn btn-success" Now, in application.js i wrote $(document).ready(function(){ $(".comments_link").click(function(){ $(".section").toggle(); }); }) The problem with this code, whatever element i choose for click event, it works. But when i use .comments_link class, it doesn't work. Why is this happening? Anything but link_to

Ajax call when clicking on a button in rails

只谈情不闲聊 提交于 2019-12-14 02:23:32
问题 I basically want to create an alert when clicking on a button, withour reloading the entire page. Into my view : :javascript function ajax_test1(field) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET", "test_ajax.xml?code=" + field.value, false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; alert(xmlDoc

Haml print at same line

我的梦境 提交于 2019-12-13 23:27:13
问题 I want to print HAML at same line %ul - @categories.each do |c| %li= c.name (#{c.posts.count}) and I recive <ul> <li>vim</li> (3) <li>bash</li> (1) </ul> How to get <ul> <li>vim(3)<li> <li>bash(1)</li> </ul> 回答1: Something like this should work: %li= "#{c.name} (#{c.posts.count})" 来源: https://stackoverflow.com/questions/8591796/haml-print-at-same-line

How HAML can recognize the end of the block?

狂风中的少年 提交于 2019-12-13 15:19:42
问题 = form_for(:subject, :url => {:action => "create"}) do |f| = render :partial => "form", :locals => {:f => f} #form_buttons= submit_tag "Create Subject" Noticed that form_for has a "do",so it needs a "end", but how does HAML knows where to end the "end" ? Sorry about my English,hope you can understand what am I talking about! 回答1: HAML uses indentation to delimit blocks in the same way the Python language does. Perhaps you should read a basic tutorial or WIKI for more information. = form_for(

Rails, MongoMapper nested Array in HAML form trouble

a 夏天 提交于 2019-12-13 07:03:54
问题 I'm getting undefined method `Carrots' for # (referencing ln#18) When trying to edit with the below form: = form_for @harvest do |f| - if @harvest.errors.any? #error_explanation %h2= "#{pluralize(@harvest.errors.count, "error")} prohibited this harvest from being saved:" %ul - @harvest.errors.full_messages.each do |msg| %li= msg .field = f.label :created_at = f.text_field :created_at, :disabled => true %br = f.label :photo = f.text_field :photo %h2 Crops - @harvest.harvested_crops.each do

Ruby on Rails Condition Broken

拥有回忆 提交于 2019-12-13 07:03:25
问题 I have Ruby on Rails 2.3.x. I have a database for a learning management system. Users are given a user ID, and take quizzes. If a user takes any number of quizzes, I want the average score to display. The score is listed in the quiz_results table as a float between 0 and 1, hence the * 100 and .round , with a user_id row as well. But if a user hasn't taken any quizzes, I want "No quizzes taken" to appear. Here's the code: -if QuizResult.find_by_user_id(@user_id).present? ="#{(QuizResult

how to store an array from a multiple select

我怕爱的太早我们不能终老 提交于 2019-12-13 05:54:37
问题 i am currently using this select = select(:schedule, :selected_players, @players.map { |p| [full_name(p), p.id] }, {:include_blank => 'None'}, "data-placeholder" => 'Add Players to Lineup', :prompt => 'Add Players to Lineup', :multiple => "multiple") and would like to store the information into an array within the database, then access this array for different pars of the site there is a copy of things im needing to know how best to store into the database, current this field value is binary

haml, blocks and partials

╄→гoц情女王★ 提交于 2019-12-13 00:39:18
问题 To clean and factor ugly views, I'd like to do the following: 1) In the view: = document_left_container do = document_information 2) In my helper: def document_left_container(&block) render partial: "/document_left_container", locals: { custom_block: block } end def document_information render partial: "document_information" end 3) Partials: For document_left_container: .foo = custom_block.call For document_information: .bar 4) The expected result: <div class='foo'> <div class='bar'> </div> <