render partial with slim-lang grunt-slim plugin throws "undefined method render" - ruby-on-rails

I'm trying to work with slim-lang for my web project. I have the following setup:
ruby 2.0
rails 4.0
node v0.10.17
This setup is working with grunt and the grunt-slim plugin.
At first glance, the slim templates compile all right, but when I try to work with partials, I get an error:
NoMethodError: undefined method `render' for #Object:0x000000029db190
Example code to reproduce:
_foo.slim:
a (href="#") click
bar.slim:
= render 'foo'
I'm a front end developer, so I don't know enough about ruby or rails. I don't understand what causes this error-- is it the grunt-slim plugin or something to do with ruby?
Any help will be appreciated!

So the grunt-slim plugin calls the command-line slim utility. I was able to reproduce the error message you're getting by creating the two example files you gave and running:
slimrb --trace bar.slim
This error is happening because a bare render method isn't part of the slim gem, it's part of rails. I was able to get the above command to work by changing bar.slim to be:
= Slim::Template.new('_foo.slim').render
This is clearly more verbose, sorry. I'm not sure if there's a better way to integrate grunt and rails' templates that would get around this issue, but you could just let rails do the rendering.

Related

Rails Console 'helper' and 'app' Appear Incomplete

Using ruby 2.3.0 and rails 4.2.5.1, I'm trying to figure some things
out using the rails console. I have several instances where app or helper seem like they have a method I want, but I often end up with the NoMethodError message. This happens even in a brand-new application where I've edited nothing and given no special options to the rails new command. For instance:
irb(main):015:0* helper.timez
... here I hit TAB to get:
irb(main):015:0* helper.timezone
... and hit ENTER, only to find:
NoMethodError: undefined method `timezone' for #<ActionView::Base:0xc662b80>
Why would tab-expansion in the console expand to methods that don't
exist? More importantly, if they're supposed to be there, why aren't
they? What can I be doing wrong?

Install generator won't see a method I defined

I'm trying to use my Engine in another app to test the install generator and it seems to be failing. I haven't used my install generator for a long time, so I'm not sure when it broke (or if it ever truly smoothly worked). My project is based off radar/forem, so I tried to borrow a lot of their code (including the generator).
Edit: My installer works for the engines test/dummy but not in other apps. Why?
GH issue: https://github.com/NJayDevelopment/mongoid_forums/issues/16
Here is the log:
$ rails g mongoid_forums:install
What is your user class called? [User]
What is the current_user helper called in your app? [current_user]
Defining mongoid_forums_user method inside ApplicationController...
insert app/controllers/application_controller.rb
Adding mongoid_forums initializer (config/initializers/mongoid_forums.rb)...
create config/initializers/mongoid_forums.rb
(erb):5:in `template': undefined method `per_page' for MongoidForums:Module (NoMethodError)
The route is successfully added, however the initializer/mongoid_forums.rb is a blank file. The method is defined exactly how radar/forem does it, what could be the error?
Here is the relevant code:
Per page method definition: https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/mongoid_forums.rb#L33
Mattr accessor:
https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/mongoid_forums.rb#L9
Initializer template:
https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/generators/mongoid_forums/install/templates/initializer.rb
Install generator at error point:
https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/generators/mongoid_forums/install_generator.rb#L47
Turns out when you try requiring mongoid_forums in pry, you'll see that an error involving decorators occurs. The issue is fixed here in my pull request to decorators: parndt/decorators#13
It's because of the way files are required and how load! is called over there.
Waiting on PR status, that is the same version that radar/forem uses as well.

undefined method `translate' for I18n:Module

On a server i had an installation of the gollum wiki. It ran fine. Now I also had to install redmine on that same server. This was a big pain, as redmine refused to run with puma. I had to mess around a lot with different gems to make it work at all.
But for some reason i now get an error from gollum, whenever i try to create a new wiki page:
NoMethodError at /create/old/git-tips
undefined method `translate' for I18n:Module
The stack trace shows that the error occurs in this line of stringex:
/var/lib/gems/1.9.1/gems/stringex-2.0.5/lib/stringex/localization/backend/i18n.rb in i18n_translations_for
::I18n.translate("stringex", :locale => locale, :default => {})
So i checked the installed packages with gem list and the required version of i18n 0.6.1 is there.
Any idea, what could be wrong and how to fix this?
For reference here's the output of gem list.
This may or may not help, but I had a similar problem on a large code base where there was an application-specific I18n module (which included some custom helper methods), but this was overriding the 't' method (a shortened form of translate).
In this case I found I could force the base-level I18n module by using two colons...
::I18n.t('thing')

Undefined method `children' for nil:NilClass since the update to Haml 3.1

Background info
I am working my way through Crafting Rails and in Chapter 4 I made a handler for "merb" templates—markdown with erb interspersed. This can be compiled into text or html, so it's perfect for mail. My "new_submission" Notification email has one template in app/views/notifications/new_submission.merb. Then in app/mailers/notifications.rb, all you need to do is
mail(:to => Person.editor.email) do |format|
format.text
format.html
end
And the single .merb template gets compiled into both the text and html part of a multipart email. Woohoo! You can read more about this in an excerpt from Crafting Rails, and you can browse around my specific implementation of it.
Somewhere, somehow, something went wrong
I updated my Gemfile about a week ago, and thought I got everything working because my pages were loading and Compass and Sass were no longer grumbling at me. For some horrible reason I didn't run any of my tests. But it turns out I've been getting this error since then whenever I call an action (such as "packlet.destroy") that tries to send this new_submission email:
ActionView::Template::Error (undefined method `children' for nil:NilClass):
app/mailers/notifications.rb:25:in `block in new_submission'
app/mailers/notifications.rb:23:in `new_submission'
app/models/submission.rb:62:in `has_been'
app/models/packlet.rb:20:in `destroy'
app/controllers/packlets_controller.rb:27:in `destroy'
Line 26 of app/mailers/notifications is the "format.html" line, shown above.
I have narrowed this down to a problem with haml/sass 3.1 by doing this bundle update more granularly. I updated Rails, ran my tests, no problems. I updated haml, ran my tests, and this pops out in four places.
Any guidance would be greatly appreciated.
This is a known issue in Haml 3.1, caused by nesting content within comments. (I learned this from haml's creator himself.)

Missing helper file error after Rails3 conversion

I'm in the midst of converting an old Rails2.3 project to 3, and I'm running into this runtime error when I load the first page:
Missing helper file helpers/activesupport.rb
Full stacktrace here
Has anyone else run into this? Looks like something changed in how helpers are loaded, but I don't see any obvious solutions.
I was able to work around the problem by created an empty file at app/helpers/activesupport.rb but I would like to know why this is happening in the first place.
Could it be a clash with ActiveSupport?
I am not sure why its even looking for such a helper - do you have a model or controller called activesupport?
I was having a similar issue with Hpricot. I had a require 'hpricot' statement in a helper, but I didn't have Hpricot in my Gemfile.
In your case, if you were explicitly requiring ActiveSupport somewhere, you would have to add it to your Gemfile (I just tried it and despite having Rails in my Gemfile, I still got the same error you were getting).

Resources