Search Results

Search found 193 results on 8 pages for 'haml'.

Page 3/8 | < Previous Page | 1 2 3 4 5 6 7 8  | Next Page >

  • How would you implement the "tell don't ask" principle in HAML?

    - by Enrique Ramírez Vélez
    Here's the thing. I have a button that, depending on the scenario, will behave, look and have different text. Here's how it, roughly, looks like at the moment: - if params[:param_A] && @statement_A %span.button.cancel_button{attribute: "value_B"} - if @statement_B = t('locale_A') - else = t('locale_B') - elsif params[:param_A] %span.button.cancel_button{attribute: "value_A"} - if @statement_B = t('locale_A') - else = t('locale_B') There's also a CSS class both buttons should have IF statement_B is true. So it is a mess. And I recently read about the "Tell, don't ask" principle which I liked very much, so I'd love to apply it here... but I'm not sure how. I know I could make a helper, but I'd like to stay away from them because reasons (I really have some valid reasons to do so, but those are beyond the scope of this question). I can resort to that as a last resource, but would rather find another solution.

    Read the article

  • When the user first visits the page I want all the checkboxes to be checked in my index page. Below is the code from my controller and index.html.haml

    - by user1760920
    I want the checkbox to be checked when the user visits the page for the first time. -# This file is app/views/movies/index.html.haml %h1 All Movies = form_tag movies_path, :method => :get, :id => 'ratings_form' do Include: - @all_ratings.each do |rating| = rating = check_box_tag "ratings[#{rating}]", "1", @checked_ratings.include?(rating), :id => "ratings_#{rating}", = submit_tag 'Refresh', :id => 'ratings_submit' %table#movies %thead %tr %th{:class => ("hilite" if @sort == "title")}= link_to "Movie Title", movies_path( :sort => "title", :ratings => @checked_ratings), :id => "title_header" %th Rating %th{:class => ("hilite" if @sort == "release_date")}= link_to "Release Date", movies_path( :sort => "release_date", :ratings => @checked_ratings), :id => "release_date_header" %th More Info %tbody - @movies.each do |movie| %tr %td= movie.title %td= movie.rating %td= movie.release_date %td= link_to "More about #{movie.title}", movie_path(movie) = link_to 'Add new movie', new_movie_path #This is my Controller class MoviesController < ApplicationController def show id = params[:id] # retrieve movie ID from URI route @movie = Movie.find(id) # look up movie by unique ID # will render app/views/movies/show.<extension> by default end def index #get all the ratings available @all_ratings = Movie.all_ratings @checked_ratings = (params[:ratings].present? ? params[:ratings] : []) @sort = params[:sort] @movies = Movie.scoped if @sort && Movie.attribute_names.include?(@sort) @movies = @movies.order @sort end id @checked_ratings.empty? @checked_ratings = @all_ratings end unless @checked_ratings.empty? @movies = @movies.where :rating => @checked_ratings.keys end end def new # default: render 'new' template end def create @movie = Movie.create!(params[:movie]) flash[:notice] = "#{@movie.title} was successfully created." redirect_to movies_path end def edit @movie = Movie.find params[:id] end def update @movie = Movie.find params[:id] @movie.update_attributes!(params[:movie]) flash[:notice] = "#{@movie.title} was successfully updated." redirect_to movie_path(@movie) end def destroy @movie = Movie.find(params[:id]) @movie.destroy flash[:notice] = "Movie '#{@movie.title}' deleted." redirect_to movies_path end end In the controller, I set the @checked_rating to be @all_rating if the @checked.rating is empty but it does not do anything. I tried putting :checked = true in the index.html.haml on the check_box_tag but that makes the checkboxes checked everytime the page is refreshed. Everytime I check a particular checkbox and hit refresh button the page loads with all the checkboxes checked. Please help me with this. Thank you in Advance.

    Read the article

  • Sass mixin not compiling?

    - by corroded
    I have previously made a mixin in sass 2.2.22 for my font sizes(it's a font converter), like so: =6.5pts :font :size 9px It has been working ever since i first made it a year ago. We just upgraded to haml/sass 3 and now whenever I try to refresh the page im working on, a sass compile error appears like so: http://grab.by/4yFE I don't get it since Sass 3 documentation says that the = declaration for mixins is NOT deprecated. I tried uninstalling haml 3.0, restarted my server and deleted the generated css file and now it apparently works. Problem is, I need haml 3 for another related project where we just started using Compass. Why is the compiler complaining when the documentation claims the declaration is not deprecated?

    Read the article

  • Get absolute (base) url in sinatra.

    - by berkes
    Right now, I do a get '/' do set :base_url, "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}" # ... haml :index end to be able to use options.base_url in the HAML index.haml. But I am sure there is a far better, DRY, way of doing this. Yet I cannot see, nor find it. (I am new to Sinatra :)) Somehow, outside of get, I don't have request.env available, or so it seems. So putting it in an include did not work. How do you get your base url?

    Read the article

  • using the :sass filter with :css

    - by corroded
    We are currently making a widget that requires some default declared styles along with it(widget html is included by javasacript, along with the default css in style tags) but the problem is i can't "chain" haml filters. What I'm trying to do is to add an internal stylesheet along with the widget like so: <style type="text/css"> p {color: #f00;} </style> <div id="widget-goes-here"> <p>etc</p> </div> We are using haml so I tried doing it with the sass filter: :sass p :color #f00 #widget-goes-here %p etc sadly, it just generated a div with a p plus the generated css code literally on top: p {color: #f00;} paragraph here I then tried using the :css filter of haml to enclose the thing in style tags(theoretically it should then turn the paragraph text color to red): :css :sass p :color #f00 #widget-goes-here %p etc But this also failed, it did generated style tags but then it just enclosed the words :sass p :color #f00 in it(it didn't parse the sass code) We did change it to :css p {color: #f00} and it worked out fine, but I still plan on doing the styling in sass(instead of plain old css) is there a way to do this?

    Read the article

  • Node.js/Express Partials problem: Can't be nested too deep?

    - by heorling
    I'm learning Node.js, Express, haml.js and liking it. I've run into a prety annoying problem though. I'm pretty new to this but have been getting nice results so far. I'm writing a jquery heavy web app that relies on a table containing divs. The divs slide around, switch back and fourth and are resized etc to my hearts content. What I'm looking for a way to switch (template?) the divs. Since I've been building in express and mimicking the chat example it would make sense to use partials. The rub is that I've been using inexplicit divs in haml, held within a td. The divs are cunstructed as follows: %tr %td .class1.class2.class3.classetc Which has worked fine cross browser. Parsing the classes works great for the js code to pass arguments around, fetch values etc. What I'd like to be able to do is something like: %tr %td .class1.class2.class3.classetc %ul#messages != this.partial('message.html.haml', { collection: messages }) Any combination I've tried with this has failed however. And I might have tried them all. If I could put a partial into that div I'd probably be set. And you can nest them as long as you use #ids instead of .classes. But if you use more than one class it breaks! I think that's the most accurate way of summing it up. How do you do this? I've checked out various templating solutions like mu.js and micro template like by John Resig. I earlier checked out this thread on templating engines. It's very possible I'm making some fundamental mistake here, I'm new to this. What's a good way to do this?

    Read the article

  • recursive html2haml

    - by yaya3
    I have many html files in nested directories which I need to convert to Haml templates I've modified the following bash script from here - http://terrbear.org/?p=277 to modify html files and not erb but I still need to modify it to be recursive ... #!/bin/bash if [ -z "$1" ]; then wdir="." else wdir=$1 fi for f in $( ls $wdir/*.html ); do out="${f%}.haml" if [ -e $out ]; then echo "skipping $out; already exists" else echo "hamlifying $f" html2haml $f > $out fi done I've named this script h2h.sh and tried going for commands like h2h.sh `find . -type d` I'm getting no output in the terminal Thanks

    Read the article

  • Passing data with Rails' link_to helper

    - by mathee
    I am implementing a question-and-answer application with Ruby on Rails. I have MVCs for Questions and Answers. In the home view (index.haml), I list the Questions like this: - @questions.each do |q| %tr %td =link_to q.title, q Next to each of those, I want to add a link that will create a new Answer and pass the id of the Question in that row (continued from the above Haml code) : %td #{link_to 'answer me!', new_answer_path, pass q.id here somehow?} I don't know how to properly pass it and then access it in AnswersController. I tried #{link_to 'answer me!', new_answer_path, :question_id => q.id}, but that was just a guess, and I don't know how to access that in AnswersController. I read the Rails API docs, and I know you can add query, too, but I still don't know how to access the value in AnswersController.

    Read the article

  • How can I get all the checked items from a submitted form with sinatra's params?

    - by 102405176597896213397
    I'm running Sinatra 1.0 with HAML, my form has a number of checkboxes, for example books I like, and you would select all the books you want. The checkbox name is "books". In sinatra params['books'] there should be an array of all the books that were checked, but it only has the last item that was checked, not an array. How can I get all the checked items? HAML: %form{:action => "/test", :method => 'post'} %input{:name=>'check',:type=>'checkbox',:value=>'item1'} item 1 %input{:name=>'check',:type=>'checkbox',:value=>'item2'} item 2 %input{:name=>'check',:type=>'checkbox',:value=>'item3'} item 3 %input{:type => "submit", :value => "send", :class => "button"} Sinatra get method post '/test' do puts params['check'] #should be an array but is last item checked end

    Read the article

  • 2 Spaces or 1 Tab, what's the standard for indentation in the Rails Community?

    - by viatropos
    I've noticed that most of the HTML/XML/HAML that gets generated from plugins uses 2 spaces instead of 1 tab. I use textmate and have tabs set to 4 spaces for HAML/HTML/XML and 2 spaces for Javascript/Ruby, but I only have to press the tab key once to get nice indentation. Pressing the space bar twice and delete twice seems like too much work :p. Do you manually type two spaces, or is some middle layer converting tabs to two spaces? Or do just a few of you use tabs?

    Read the article

  • link_to_remote does not generate correct url in Haml

    - by mathee
    In Haml, I've been trying to get the following link_to_remote call to work. It's called from the /questions/new view. #{link_to_remote image_tag('x.png'), :url => {:controller => 'questions', :action => 'remove_tag_from_cart'}} I've tried the following variations. #{link_to_remote image_tag('x.png'), :url => {:controller => :questions, :action => :remove_tag_from_cart}} #{link_to_remote image_tag('x.png'), :controller => 'questions', :action => 'remove_tag_from_cart'} #{link_to_remote image_tag('x.png'), :controller => :questions, :action => :remove_tag_from_cart} In every case, I get the following link: /questions/new#. I'm not sure why! I also have the following in routes.rb, thinking that was the problem... map.connect ':controller/remove_tag_from_cart', :action => 'remove_tag_from_cart'

    Read the article

  • How to add and remove nested model fields dynamically using Haml and Formtastic

    - by Brightbyte8
    We've all seen the brilliant complex forms railscast where Ryan Bates explains how to dynamically add or remove nested objects within the parent object form using Javascript. Has anyone got any ideas about how these methods need to be modified so as to work with Haml Formtastic? To add some context here's a simplified version of the problem I'm currently facing: # Teacher form (which has nested subject forms) [from my application] - semantic_form_for(@teacher) do |form| - form.inputs do = form.input :first_name = form.input :surname = form.input :city = render 'subject_fields', :form => form = link_to_add_fields "Add Subject", form, :subjects # Individual Subject form partial [from my application] - form.fields_for :subjects do |ff| #subject_field = ff.input :name = ff.input :exam = ff.input :level = ff.hidden_field :_destroy = link_to_remove_fields "Remove Subject", ff # Application Helper (straight from Railscasts) def link_to_remove_fields(name, f) f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)") end def link_to_add_fields(name, f, association) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render(association.to_s.singularize + "_fields", :f => builder) end link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)} \")")) end #Application.js (straight from Railscasts) function remove_fields(link) { $(link).previous("input[type=hidden]").value = "1"; $(link).up(".fields").hide(); } function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g") $(link).up().insert({ before: content.replace(regexp, new_id) }); } The problem with implementation seems to be with the javascript methods - the DOM tree of a Formtastic form differs greatly from a regular rails form. I've seen this question asked online a few times but haven't come across an answer yet - now you know that help will be appreciated by more than just me! Jack

    Read the article

  • Pair of blocks in each?

    - by Aleksandr Koss
    As in the standart cycle: - @goods.each do |good| ??? ...to organize this (HAML): .columns-wrapper .column First good .column Second good .column Third good .columns-wrapper .column Fourth good .column Fifth good .column Sixth good

    Read the article

  • accessing Ruby variable(from model or controller) in SASS

    - by corroded
    Is there a way to access ruby variables in sass or do i have to make a custom function for it? What im trying to do is to generate a stylesheet for each user so in the controller, i do something like: def show respond_to do |format| format.css{render :partial => "styles"} end end then in the view name _styles.haml i do this: :sass #header :background url(user.banner.url) is this possible at all?

    Read the article

  • testing helpers with 'haml_tag'

    - by crankharder
    module FooHelper def foo haml_tag(:div) do haml_content("bar") end end end When I test this I get: NoMethodError: undefined method `haml_tag' This code is perfectly valid and works in a development/production environment. It's something to do with having the haml helpers properly loaded in the test environment. Thanks!

    Read the article

  • Pass selected option to remote_function with Ruby on Rails

    - by mathee
    I have a list of options generated by the following Haml code. %select#tags{:onchange => remote_function(:url => {:action => :display_tag_cart}, :with => 'Form.Element.serialize(this)'), :prompt => 'Choose a Tag'} %option{:value=>""} Choose a Tag -Tag::TAGS.each do |t| %option{:value=>t.id} =h t.name Form.Element.serialize(this) does not work. How do I pass the value of the selection to display_tag_cart?

    Read the article

  • Looking For A Good HTML Templater for PHP

    - by Ygam
    That's an HTML templater, not a php templater, not java or whatever. I am looking for something like HAML for PHP. I tried the 2 projects for PHP, PHAML and PHPHaml both of which are suffering from serious bugs. Do you know of any good html templater out there, preferably for PHP? EDIT I''m looking for something that can turn this <h1>Heading</h1> <p>entry</p> <blockquote>quote</blockquote> to something like this h1 : heading p : entry blockquote : quote something like what phphaml does

    Read the article

  • Rails belongs_to issue in the views

    - by Jacobo Tibaquira
    Hi, Im having problems with an association in rails: Currently I have Post and User models, and the relationship is set this way: class User < ActiveRecord::Base attr_accessible :username, :name, :lastname has_many :posts end class Post < ActiveRecord::Base attr_accessible :title, :body belongs_to :user end However, in my app/views/posts/index.html.haml when Im trying to access the username for the post I get this error: undefined method `name' for nil:NilClass This is my view: - title "Posts" %table %tr %th Title %th Body %th Author - for post in @posts %tr %td= h post.title %td= h post.body %td= h post.user.name %td= link_to 'Show', post %td= link_to 'Edit', edit_post_path(post) %td= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %p= link_to "New Post", new_post_path Any thoughts of what Im doing wrong will be appretiated

    Read the article

  • How can I keep a div's scrollbar at the bottom of the div using jQuery?

    - by dannytatom
    I have a div called #output, styled with overflow: scroll;. Using jQuery.ajax, it's being updated every x second. I'd like to have it so that when the scrollbar appears (after the divs filled up), it should continously stay at the bottom of the div instead of the top, like most chat clients do. I'm sure there's a way to do this, I just can't seem to find it. Here's the Sass #output :margin 0 0 10px 0 :padding 10px :height 500px :overflow scroll :background #111111 :border 1px solid #000000 :color #8e8e8e and the Haml is just a simple #output = @output

    Read the article

  • InvalidAuthenticityToken for JQuery despite setting authenticity token

    - by user117046
    I'm getting an InvalidAuthenticityToken despite adding in corresponding authenticity tokens in the jquery response. Is there an error in the code, or is there another, root problem? I appreciate any comments. Thanks! Using: Rails 2.3.3, Ruby 1.8.6, Webrick, JQuery 1.3.2 layout/networks.html.haml = token_tag = javascript_tag "window.AUTH_TOKEN = '#{form_authenticity_token}';" javascripts/application.js $(document).ready(function() { // All non-GET requests will add the authenticity token // if not already present in the data packet $(document).ajaxSend(function(event, request, settings) { if (typeof(window.AUTH_TOKEN) == "undefined") return; // <acronym title="Internet Explorer 6">IE6</acronym> fix for http://dev.jquery.com/ticket/3155 if (settings.type == 'GET' || settings.type == 'get') return; settings.data = settings.data || ""; settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(window.AUTH_TOKEN); }); ajaxLinks(); }); The rendered html has: <input name="authenticity_token" type="hidden" value="ZaXj3ACQl+8JKtaDAUoxtSsqzEagSPyHbS25ai9qWCw=" /> <script type="text/javascript"> //<![CDATA[ window.AUTH_TOKEN = 'ZaXj3ACQl+8JKtaDAUoxtSsqzEagSPyHbS25ai9qWCw='; //]]> </script> and breakpointing through, shows that window.AUTH_TOKEN has been set. Any help to resolve this would be great.

    Read the article

  • Rails CSS not Loading using Heroku

    - by eWizardII
    I have the following site set up here on Heroku - http://www.peerinstruction.net/users/sign_up the issue is that I have updated the css yet it is not being actively reflected on the site, it just shows a textbox, with some edited/custom fonts. I have attached the css file in the following gist - https://gist.github.com/f74b626c54ecbb60bbde The signup page controller: !!! Strict %html %head %title= yield(:title) || "Untitled" = stylesheet_link_tag 'application', 'web-app-theme/base', 'web-app-theme/themes/activo/style', 'web-app-theme/override' = javascript_include_tag :defaults = csrf_meta_tag = yield(:head) %body #container #header %h1 %a{:href => "/"} Peer Instruction Network #user-navigation %ul.wat-cf %li .content.login .flash - flash.each do |type, message| %div{ :class => "message #{type}" } %p= message = form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :class => "form login" }) do |f| .group.wat-cf .left= f.label :email, :class => "label right" .right= f.text_field :email, :class => "text_field" .group.wat-cf .left= f.label :password, :class => "label right" .right= f.password_field :password, :class => "text_field" .group.wat-cf .right %button.button{ :type => "submit" } Login /= link_to "Sign In", destroy_user_session_path #box = yield The signup pages haml file: %h2 .block .content.login .flash - flash.each do |type, message| %div{ :class => "message #{type}" } %p= message = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| = devise_error_messages! %div = f.label :firstname %br/ = f.text_field :firstname %div = f.label :middlename %br/ = f.text_field :middlename %div = f.label :lastname %br/ = f.text_field :lastname %div = f.label :email %br/ = f.email_field :email %div = f.label :password %br/ = f.password_field :password %div = f.label :academic %br/ = f.text_field :academic %div= f.submit "Continue" = render :partial => "devise/shared/links" I used web-app-theme to create an activo theme and then modify it.

    Read the article

  • Help me understand dynamic layouts in Sinatra

    - by thermans
    Help me understand this; I'm learning Sinatra (and Rails for that matter, er, and Ruby). Say I'm doing a search app. The search form is laid out in one div, and the results will be laid out in another. The search form is rendered into the div by a previous view (maybe from a login form). I want to process the form params, perform the search, and render the results into the results div. If I have a single "yield" in the layout and render the divs from different views, the results div erases the search div when it renders. If I define the divs in the default layout, then just render the content, obviously the layout will be messed up: there would have to be two "yields" and I don't think Sinatra supports passing blocks in to yields. I tried foca's sinatra-content-for plugin, and that seems closer to what I need. But I can't figure out where to place the "yield_content" statements. If I have this haml in my layout: #search -# search form = yield_content :search #results -# search results = yield_content :results ... this in my search view: - content_for :search do %form{:method => "post"... etc. ... and this in the results view: - content_for :results do %table{:class => 'results'... etc. This sort of works but when I render the results view, the search div is emptied out. I would like to have it remain. Am I doing something wrong? How should I set this up?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8  | Next Page >