Tag: haml

Rails 2.3.2试图渲染ERB而不是HAML

Rails突然试图渲染ERB而不是Haml,我无法弄清楚原因。 我创建了新的rails项目,重新安装了Haml,并重新安装了Rails。 这正是我在制作应用程序时所采取的步骤(Rails 2.3.2): rails> rails test rails> cd test rails\test> haml –rails . rails\test> ruby script\generate model user email:string password:string rails\test> ruby script\generate controller users index rails\test> rake db:migrate 这是UsersController的样子: class UsersController < ApplicationController def index @users = User.all end end 我的路线: ActionController::Routing::Routes.draw do |map| map.resources :users end 我现在创建views \ users \ index.html.haml : […]

Haml -Illegal nesting:在纯文本中嵌套是非法的

我在使用HAML时我的代码中遇到了一个奇怪的错误,我的代码在我的本地机器上运行,但是当我部署它时,我收到以下错误 ActionView :: Template :: Error(非法嵌套:在纯文本中嵌套是非法的。): 我的代码看起来像这样 %td{ :style => ‘width:10px’ } = link_to(‘Dashboard’, dashboard_admin_clients_account_path(client)) if client.is_member? = link_to(‘Edit’, edit_admin_clients_account_path(client)) – if client.removed_at.nil? = link_to(‘Delete’, admin_clients_account_path(client), :method => :delete, :confirm => ‘Are you sure you want to delete’) – else = link_to(‘Restore’, restore_admin_clients_account_path(client)) 我是HAML的新手

为什么删除方法给我错误的路径? 同

我有简单的删除链接: = link_to “Delete”, messages_path(message.id), :method => :delete 给我错误: No route matches [DELETE] “/messages.316″ 如何解决这个问题? 我有ruby 1.9.3p0 Rails 3.1.1 我的routes.rb resources :messages do collection do get :outbox end end 当我将其更改为message_path我收到wrong number of arguments (0 for 1) – > full_trace: https ://gist.github.com/1967988 – >所有文件: https : //gist.github.com/1967994 outbox_messages GET /messages/outbox(.:format) {:action=>”outbox”, :controller=>”messages”} messages GET /messages(.:format) {:action=>”index”, […]

有条件地使用haml中的content_for包装器

我正在尝试找到更干的方法来执行以下操作: – if request.xhr? :javascript {my javascript} – else = content_for :scripts do :javascript {my javascript} 我在许多haml文件中重用了这个模式,所以我想知道抽象出条件逻辑的最佳方法是什么。 理想情况下,我想在我的haml文件中实现以下内容: optional_content_for :scripts do :javascript {my javascript} 谢谢!

Rails,MongoMapper在HAML中嵌套数组形成麻烦

我越来越 用于#的未定义方法`胡萝卜’ (引用ln#18) 尝试使用以下表单进行编辑时: = 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 |harvested_crop| = f.label :harvested_crop[‘crop’] […]

在haml中取消内联链接

所以我想在电子邮件表单中找到标题旁边的删除链接。 但是,我的铁路伏都教显然非常弱。 它逃脱了HTML,我无法弄清楚如何得到它。 任何提示? = f.input :email, :label => “Email ” + link_to_remove_fields(“[x]”, f) [编辑]哦,是的,这也做同样的事情: = f.input :email, :label => “Email #{link_to_remove_fields(“[x]”, f)}” 这是我的助手方法…… 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, “add_fields(this, \”#{association}\”, \”#{escape_javascript(fields)}\”)”) end

安装gem“joyride-rails”时的依赖性错误

我的rails版本是3.2.12 。 我正在尝试在我的应用程序中实现gem “joyride-rails”, “~> 0.0.14” ,但它与我的其他一些gem发生冲突。 已经在我的Gemfile中了: gem “haml-rails”, “>= 0.4” gem ‘activeadmin-mongoid’, github: ‘elia/activeadmin-mongoid’, branch: ‘active-admin-spec-suite’ 当我运行bundle命令时,我收到此错误: Bundler could not find compatible versions for gem “haml”: In Gemfile: joyride-rails (~> 0.0.14) ruby depends on haml (~> 3.1) ruby haml-rails (>= 0.4) ruby depends on haml (4.0.3) 所以,如果我添加gem “haml”, “~> 4.0.3” ,新的捆绑冲突是: Bundler could […]

Rails:如何呈现重复的表单块?

为了不重复自己,我想创建一个以特定方式呈现表单块(文本字段或文本区域)的函数。 我想要一个像这样的结果(使用Haml和twitter-bootstrap): .form-block.input-prepend %span.add-on> %i.icon.icon-home = f.text_field :name, :value => @store.name, :placeholder => ‘Company Name’ 为此,我创建了一个文件views/layouts/_form-block.html.haml ,其中插入了以下代码: .form-block.input-prepend %span.add-on> %i{ :class => “icon icon-#{icon}” } = yield 我在视图中使用以下方法调用块: – render :template => ‘layouts/_form-block’, :locals => { :icon => ‘home’ } do = f.text_field :name, :value => @store.name, :placeholder => ‘Company Name’ 但它不起作用。 我有以下错误’nil’ is not […]

Ruby on Rails条件破碎

我有Ruby on Rails 2.3.x. 我有一个学习管理系统的数据库。 为用户提供用户ID,并进行测验。 如果用户进行任意数量的测验,我希望显示平均分数。 得分在quiz_results表中列为0到1之间的浮点数,因此* 100和.round包含user_id行。 但是如果用户没有参加任何测验,我想要”No quizzes taken” 。 这是代码: -if QuizResult.find_by_user_id(@user_id).present? =”#{(QuizResult.average(‘score’, :conditions => ‘user_id = #{@user.id}’) * 100).round}%” -else %em No quizzes taken 问题在于,无论如何,即使有quiz_results条目,仍然会出现”No quizzes taken” 。 我究竟做错了什么?

检测current_page? 在导航部分不工作

这是’shared / subnav’部分的代码。 当我点击链接时,它显示错误No route matches {:action=>”show”, :controller=>”location”}但是路由已定义。 我认为下面的代码存在一些问题。 -if current_page? location_path = link_to ‘Edit Location’, edit_location_path -if current_page? user_path = link_to ‘Edit User’, edit_user_path -if current_page? alert_path = link_to ‘Edit Alert’, edit_alert_path 这是我的路线 location GET /locations/:id(.:format) locations#show user GET /users/:id(.:format) users#show alert GET /alerts/:id(.:format) alerts#show