Rails Console 'helper' and 'app' Appear Incomplete - ruby-on-rails

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?

Related

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.

Conflict between Rails Admin and Impressionist gems

I'm using the latest version of the Impressionist and Rails Admin gems, and wondering if anyone could shed some light on an annoying conflict I'm experiencing. The problem is roughly documented here - https://github.com/sferik/rails_admin/issues/1315, yet the vaguely described solution is not working for me. When I have the line is_impressionable in my Listing model, I get an error when starting my Rails server with rails s:
...rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `is_impressionable' for Listing(no database connection):Class (NameError)
If I first start the server, and then add the 'is_impressionable' line, everything works fine, so the problem only occurs during initialization. I don't fully understand the initialization process, so am not sure how to go about getting this to work.
I have tried moving all my rails_admin model configuration options to their respective models, rather than in the initializer, which had no effect. I also have the following line in my initializer:
config.included_models = [Listing,ListingImage,AllOtherModelsHere...]
I have tried adding single quotes around these model names, which results in the following errors, as described in the github issue here
[RailsAdmin] Could not load model Listing, assuming model is non existing. (undefined local variable or method `is_impressionable' for Listing(no database connection):Class)
Any ideas what else I can try to make these gems work together? I don't want to have to remove the is_impressionable line every time I want to restart the server or generate a migration...
Not sure if the same issue that I had but yet I will post what worked for me just in case someone struggles with this too:
Im on a ruby 2.1.5 project with rails 4.2.0 and among other gems I'm using rails admin.
I run into several weird problems trying to set this up. For instance if I added the is_impressionable call within one of my models for some reason the execution of that file stopped there and I started getting weird errors like any method declared below the is_impressionable failed with undefined error.
So what I end up doing was:
class MyModel < ActiveRecord::Base
include Impressionist::IsImpressionable
is_impressionable
end
So this solved my issue and now i can access #my_model_instance.impression_count as expected.
I changed every occurrence of Klass to 'Klass'.constantize in initializer.

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

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.

Rapidfire gem and undefined local variable or method when logged in (Survey creation gem)

I am trying to implement Rapidfire gem into my website (https://github.com/code-mancers/rapidfire). It all goes smoothly until i try to access the surveys with an active session, it shows this error:
NameError in Rapidfire/question_groups#index
Showing /home/javier/Sites/IIC2154-2013-2-Grupo1/app/views/layouts/application.html.erb where line #31 raised:
undefined local variable or method `universities_url' for #<#<Class:0xa5728e4>:0xb4fda8cc>
Not only the route shown in the picture is dead but all the rest of the routes of the application. I use devise to create users and manage sessions.
Is there anyone who has used this gem or might know what might be going on?
I am using ruby 1.9.3 and rails 3.2.14
I go through this by setting the path instead of the variable, ex. "/universities" instead of universities_url, it's not a clean way to do it but it worked.
Edit:
After a little research I found a clean way to do this. Add main_app to the route that isn't working for that route will be main_app.universities_url

NoMethodError in rails

The extracted source is below :
Showing /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/templates/rescues/diagnostics.erb where line # raised:
private method `gsub' called for #<NoMethodError: undefined method `closed?' for nil:NilClass>
Extracted source (around line #):
RAILS_ROOT: /home/sharath/Desktop/RORWorkspace/ITPLOW1
It was working before installing Sunspot: A Solr-Powered Search Engine for Ruby.
I am working in Ubuntu 10.04.
I'd need to see the full stacktrace to be sure, but this is actually probably an unhelpful HTTP connection error message bubbling up out of RSolr (the library the Sunspot uses for the low-level Solr connection). Is Solr running (i.e., did you run rake sunspot:solr:start)? Can you access http://localhost:8982/solr/admin ?
What's probably happening is you're attempting to do a substitution on some variable which you thought you were initializing, but neglected to give a real value.
For instance, if you had a form where for a Message and one of the the properties you want is the content, you would normally retrieve that information in the controller with
params[:message][:content]
And if you wanted to filter it, you would do something like
params[:message][:content].gsub(/<[^>]*>/,"")
But if the user didn't enter anything into the content field, the params[:message][:content] variable wouldn't be set. Therefore it's null and you're attempting to do nil.gsub

Resources