Ruby on Rails stopped working after netbeans installation? - ruby-on-rails

2 days ago i succesfully installed Ruby On Rails and started playing with a tutorial. Every was going fine and ws happy. Then today I wanted to continue my tutorial but something did work as usal. First i got this error
ActiveRecord::ConnectionNotEstablished
Hmm googled a bit then thought I should try starting a new project and when i tried to generate a controller i got this message
me#lenovo:~/ror/blog$ rails g controller posts
/home/me/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.2.10/lib/execjs/external_runtime.rb:130:in `which_unix': undefined local variable or method `cmd' for #<ExecJS::ExternalRuntime:0xae47d84> (NameError)
Then I remembered that I installed Netbeans 6.9.1 and RoR module later that day after all things went well. Could it be Netbeans screwing with my RoR installation?
Anyone knows how to reset this? I wont mind getting rid of netbeans if that the deal
Using Ubuntu 11.10

Looks like that there is a mismatch in the methods' variable name; it should be "cmd" but it is "name"
/Users/kj/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.2.10/lib/execjs/external_runtime.rb:130:in `which_unix': undefined local variable or method `cmd' for #<ExecJS::ExternalRuntime:0x00000100bf0b48> (NameError)
A quick peek at the file in question reveals:
def which_unix(name)
if File.executable? cmd
cmd
else
path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |path|
File.executable? File.join(path, cmd)
}
path && File.expand_path(cmd, path)
end
end
Change the method's variable name from "name" to "cmd", save and enjoy!
—Kai

Since I haven't touched NetBeans for a long time, my answer would be a clear no.
What I do suspect though, is that ruby 1.9.2-p290 introduces this error. I did upgrade today and bam; it failed on my system the very same way as it did on yours. Thus ... 1.9.2-p290 is the culprit.
--Kai
P.S.> Glad that I could be of help...

Related

Rails method global params kind_in error when upgraded

I've recently done an rails and ruby upgrade, we don't have strong params in the app (I know it's legacy).
So the way it's done in the app we have the following
def all_params_permitted(this_params = nil)
this_params = params if this_params == nil
this_params.permit!
this_params.each do |i, v|
if v.kind_in?([Hash, ActionController::Parameters])
all_params_permitted(v)
end
end
end
Which loops through all params and just accepts everything, all_params_permitted is called throughout the app I would love to add strong params but that's a no-go for now.
The issue in the above method is kind_in? the upgrade I did for this app was rails 5.0.3 to rails 6.1+ and went from ruby 2.2.6 to ruby 3.0.1 so I'm not sure why kind_in? has stopped working. This is an old app (built-in rails 2) so not sure if this has been deprecated.
Any help here would be great.
Edit
I have tried kind_of? but no dice.
the upgrade I did for this app was rails 5.0.3 to rails 6.1+ and went from ruby 2.2.6 to ruby 3.0.1
This is asking for trouble. It is strongly advised to try upgrading one minor version at a time (e.g. rails 5.0 --> 5.1 --> 5.2 --> 6.0 --> 6.1), otherwise you're very likely to break things with little information on why it's stopped working/how to fix it.
Likewise for ruby versions... At an absolute minimum I'd postpone the final upgrade to ruby v3 until your application works fine under ruby 2.7.
I'm not sure why kind_in? has stopped working
Nor am I, because that's a custom method. You haven't show us how it's defined, and nor have you shown us the error message, so it's impossible for me to say with confidence what's gone wrong.
My guess is that it's implemented something like this:
class Object
def kind_in?(classes)
classes.any? { |c| self.kind_of?(c) }
end
end
i.e. it's a little wrapper around the built-in kind_of? method.
And with that said, I still have no idea why this would have "stopped working" due to a ruby and/or rails upgrade.
Not sure about kind_in?, also didn't find any reference to that method, also as you have not posted the error so not sure about your issue. is_a?, kind_of?, instance_of? are few methods that check the object class but they check only a single class. Looking at your code one option for your condition could be:
if [Hash, ActionController::Parameters].include?(v.class)
which will check if it belongs to one of these classes.

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.

How to get all files in image directory Rails4 in array

I have migrated from Rails3 to Rails4. The following code returns Array in Rails3 but in Rails4 it returns string with illegal character.
Dir.glob("app/assets/images/flowers/*")
sample output in Rails3
["app/assets/images/flowers/rose.png", "app/assets/images/flowers/lilly.png"]
output in Rails4
"\x04\b[dI\"8app/assets/images/flowers/rose.png\x06:\x06ETI\"4app/assets/images/flowers/lilly.png"
How to get same output format as in Rails3?
try this
files = Dir.glob("app/assets/images/flowers/*").map do |f| File.basename f end
Dir has nothing to do with Rails — it's pure Ruby class. Here is the API reference to it. According to API it should always return an Array. My guess is that you messed up something in your Ruby installation while you were upgrading Rails 3 to 4.
I think best bet will be a clean installation of ruby/rails. You could also try to run Dir.glob() from both IRB and rails console to see where the mistake happens; and start from there.

My rails 3 engine's controller is only found by rails every second page refresh, otherwise returns LoadError

i'm developing a rails 3 engine but really having troubles getting the
controller to load every time.
every second time I visit the page I get;
LoadError in Webedit/public filesController#index
Expected /home/anko/.rvm/gems/ruby-1.9.2-p136/bundler/gems/webedit-3e02394235c3/app/controllers/public_files_controller.rb
to define PublicFilesController
to reproduce (assuming bash, ruby 1.9.2 and rails 3);
rails new webedit-test
cd webedit-test
echo "gem 'webedit', :git => 'https://github.com/ankopainting/webedit.git', :tag => 'v0.0.3'" >> Gemfile
bundle install
rails server
then goto http://localhost:3000/public
it will either say "hi" or an error.. refresh to see it change to the
opposite behaviour.
any help would be greatly appreciated.. I've spent some time in ruby
debugger but need to understand a lot about how rails works to get a
meaningful result.
I used the source code you provided and added a directory under controllers. Seems to work fine now. Since you have the controller inside a module, you need to create this directory structure:
app/controllers/webedit/public_files_controller.rb
Not exactly sure why it was loading every other time, though.

unable to save a model from rake task

I am writting a rake task that would connect to a legacy ORACLE database, get some 'issues' records from a helpdesk application, apply some transformation and store it in another database (Redmine).
The problem is that even though the script runs smoothly on Windows, it fails to run on RHEL 5. The library files are all installed on RHEL 5 and there are no connection errors as such. The script fails on a line '_issue.save' (where _issue is a model of type Issue 0n Redmine)!! There is no error (Just that _issue.save returns false). I've been stuck for the last 2 days on this one.
Any suggestions would be extremely helpful.
I am using Rails 2.1.2, Ruby 1.8.6 (patch level 111) and Rake 0.8.1
Thanks in advance.
No errors, but save returns false means validation might have failed. You can output the validation errors like so:
_issue.errors.each_full { |msg| puts msg }
Here's a bit more info on the each_full method.
I would create some tests and run them on the RHEL server to see where the issue is. I would use RSPEC, but test/unit can get you there as well.

Resources