haml-rails on rails 4.0?
I'm using haml-rails (0.4)
in a rails 4 project and everything is working
Template not found with HAML on Rails 4
While Rails is generally pretty good about picking up on changes made to your application when in the development
mode, any modifications to files outside of app/
and config/routes.rb
do require a restart.
If you're using the rails server
method, stop and start that. If using a system like Pow then touch tmp/restart.txt
.
Alterations to Gemfile
require an explicit restart as this might change something dramatic like the version of Rails used.
Rails 4.0.2 haml version of form_for drive me crazy
I found your problem, one was related to indentation(if-block) and other was an extra comma(submit button).
%h1{:class => ["page-header"]} New Ticket
= form_for(@ticket, :url => { :action => "create" }) do |f|
= if @ticket.errors.any?
%h2 #{pluralize(@ticket.errors.count, "error")} + " prohibited this post from being saved:" ### code indentation done as it belongs to if block
%ul
= @ticket.errors.full_messages.each do |msg|
%li = msg
%p
= f.label :subject
= f.text_field :subject
%p
= f.label :body
= f.text_area :body
%p
= f.submit :class => "btn btn-primary" ### Removed comma
= link_to 'Back', tickets_path
`undefined method `[]' for nil:NilClass` in Rails 4.0.1 and HAML
Looks like it's related to the version of protected_attributes gem interacting unfavorably with rails 4.0.1. Try upgrading to protected_attributes 1.0.5.
https://github.com/thoughtbot/factory_girl_rails/issues/115
Railscasts196, Rails 4, simple_form, JS, haml
Actually, nowadays there's a better way, using the cocoon gem.
It's very simple and I've had great success using it ;) hope you do too!
Capybara::Poltergeist::MouseEventFailed after Haml update (4.0.7 = 5.0.2) [RAILS]
Solved:
The solution was to put the data attributes value in an interpolated string like this:
%p.dialog{'data-attribute' => "#{t('you_are_on_a_device', type: '<a href="http://mywebsite.nl/type">small</a>').html_safe}", hidden: true}
and in my config/initializers/haml.rb
Haml::Template.options[:escape_html] = false
It was because of the html escaping that has become standard in HAML 5.0.0, where it wasn't in HAML 4.0.7
Haml / Rails 4: Conditions - repeating code inside
You could do something like the following:
- if current_user.is_seeking_job && current_user.is_seeking_contract
- sort_order = "sort < ?"
- sort_param = 2
- else
- sort_order = "sort > ?"
- sort_param = 1
- @jobsforyou.where.not(user_id: current_user, is_finished: true, is_active: false).where(sort_order, sort_param).limit(10).each do |job|
However, this solution is a violation of the separation of concerns principle - your view should (ideally) only be displaying data, not querying the database. I'd suggest moving the queries and associated logic somewhere more appropriate, like model methods or scopes.
Related Topics
Upsert Multiple Records with Mongodb
What's Wrong with the Square and Rectangle Inheritance
Rails 3 Caching: Expire Action for Named Route
Overriding Model in Gem, Adding Callback and Methods
Error Building Ruby in Sublime Text Editor
How to Change Ruby to Version 1.9.3 (Again) with Rvm
Rails Error Message Displays Key and I Only Want Value
Ruby: Cannot Install Watir Gem on Windows
Ruby Private Attr_Accessor and Unexpected Nil
Problem Running Thinking Sphinx with Rails 2.3.5
How to Access Current_User Object in Model
How to Execute 2 or More Commands in the Same Ssh Session
Include Erb Delimiters Inside of a String in an Erb Block
What Orm to Use in One Process Multiple Db Connections Sinatra Application
Updating from Rails 4.0 to 4.1 Gives SASS-Rails Railties Version Conflicts