How to actually use rails-settings? - ruby-on-rails

I'm trying to use rails-settings gem but i'm not sure how to do that.
I've added ledermann-rails-gem gem to Gemfile, runned bundle install, generated a migration based on what's written in wiki, runned rake db:migrate, restarted a server and now, when i'm trying to do anything from rails-settings wiki, i'm getting an error.
Let's say i want to create new variable so i'm putting this code to my controller:
Settings.foo = "bar"
It gives me the following error:
uninitialized constant ApplicationController::Settings
I'm quite 'fresh' in rails development and probably there is some small thing which wasn't mentioned in the wiki because it's obvious (but not for me!). Any help would be appreciated

Related

Ruby on Rails Vacuum Gem

I am new to Ruby on Rails and I am trying to access the Amazon Product API using the Vacuum Gem. Based off this code https://gist.github.com/frankie-loves-jesus/89d24dd88579c7f912f3 I am getting an error at the first line
request = Vacuum.new('GB')
telling me that I have an "Uninitialized constant AmazonAPIController::Vacuum" every example on this gem tells me to use this line of code but I can't understand how to fix the error. It seems to be as simple as putting the code into my controller and showing it.
You didn't add the gem to your Gemfile I guess and didn't run bundle install afterwards. Also you should make sure to restart your Rails server after every change in your Gemfile.
If all that doesn't help, you also could try to just gem install vacuum and then require 'vacuum' in the file you are using (but I would recommend getting it to work on another way).

Controller not recognizing installed Gem

Okay, I know this is a bit of a simple question, but I can't seem to get it to work. I have installed the SmarterCSV gem in my Rails 4 app and am trying to use it in my controller like so:
SmarterCSV.process("/files/csv_file.csv")
I can do this exact process in the rails console for this app, but I cannot seem to get it to work in my controller. Every time I just get the Rails Dead Screen saying uninitialized constant MyController::SmarterCSV. I have tried adding the line
require 'smarter_csv'
But that also breaks to the Rails Dead Screen with the error cannot load such file -- smarter_csv
Any help would be greatly appreciated, Im not entirely sure what I can do...
you can try require 'smarter_csv/smarter_csv' as this is the path of the file in the gem https://github.com/tilo/smarter_csv/blob/master/lib/smarter_csv/smarter_csv.rb
Don't forget to restart your application after bundle install

how to set up nulldb in rails with rspec?

I'm almost new to rails development. I'm currently reading Avdi Grimm's Objects on Rails for having a #SOLID design in my rails apps instead of being forced to some conventions which will create mess and unreadable code and design.
I wanna setup nulldb and use it in my fast specs which are testing the business logic of the application but I can't get it to work. I read the installation guide at nulldb GitHub page here -> https://github.com/nulldb/nulldb. I installed the activerecord-nulldb-adapter gem and put it also in my Gemfile and ran the bundle install command so it's completely installed now. I have a spec_helper_lite.rb file which I use in my fast specs so I though it's a good idea to setup nulldb in it. Here's the code for nulldb part in my spec_helper_lite.rb file:
require 'nulldb_rspec'
def setup_nulldb
schema_path = File.expand_path("../db/schema.rb", File.dirname(__FILE__))
ActiveRecord::Base.establish_connection(:adapter => :nulldb,
:schema => schema_path)
NullDB.nullify(:schema => schema_path)
end
def teardown_nulldb
NullDB.restore
end
then I require this spec_helper_lite.rb in my fast specs and I call the setup and teardown nulldb method in before and after methods of my spec. when I run the specs I'll get the error Uninitialized Constant ActiveRecord::ConnectionNotEstablished (NameError). I tried different things like removing that establish_connection line in the setup_nulldb and I'll get the same error. I even required 'active_record' in my spec_helper_lite just to see what will happen and then I'll get the error "undefined method nullify" for NullDB module and obviously the spec became completely slow cause of requiring active_record. I searched a lot about how to setup nulldb and everything I saw explained about setting it up this way but it doesn't work for me. I use nulldb version 0.2.1, rails 3.0.0 and rspec 2.0.1
I appreciate your help about how to set this up correctly. Thanks in advance.
Sam
I was having similar issues (but using minitest, and activerecord independent of rails). I tried all the same stuff you mentioned. Turns out I was just using whatever was in rubygems. It looks like updating my Gemfile to pull directly from github resolved the issue:
group :development, :test do
gem 'activerecord-nulldb-adapter', :git => 'git://github.com/nulldb/nulldb.git'
end
You'll want to bundle install again after updating.

I'm Getting An Uninitialized Constant Error From A Recently Installed Gem. How do you fix this?

I recently installed the Citier Gem. Its Gem a solution for simple Multiple Class Inheritance in Rails. After setting up models per the instructions and running Rake, I am getting the following error:
uninitialized constant Books::Writable
*/citier/core.ext.rb:33:in 'create_citier_view'
Its been my experience that this error message usually means the Gem is not installed properly, but I've checked my Gemfile and did a Bundler Show command and everything seems to be in order. Apparently, the core.ext file referenced in the error is supposed to be extending ActiveRecord to create views that are utilized for Multiple Class Inheritance.
I checked all the usual places for the problem but can't seem to figure this out. In suggestions or ideas would be greatly appreciated. I've been stuck on this one for a couple of days now.
Thanks for you input.
Simply type require 'rails_sql_views' in config/application.rb
U may need install gem rails_sql_views

Creating rails 3 gems: Gems installing successfully, but no functionality

I'm trying to create my first rails gem with jeweller - it's a very simple demo gem with just a "Tester" model and a "Frog" scaffold.
The gem packages up just fine, gem contents "testgem" confirms the desired files are packaged into the gem, and when I "bundle install" it, everything seems to go OK & the gem is in the list of installed gems.
...BUT - I'm not getting any functionality. The activerecord model isn't recognised from the command line (Command "Tester" returns "uninitialized constant Tester"), and the controllers aren't being found either, even when I manually add the resources to config/routes.
This is my first self-built gem, so I could be missing something simple. I've tried placing the necessary files in both [GEM_ROOT]/lib/app/ and [GEM_ROOT]/app/, with gem.path set to [{lib}//, {app}//*].
Any suggestions most appreciated. ;-)
Ach - terribly embarrassing - 30 mins after posting I figured it out.
In case anyone else is wondering: In the gem, I wasn't directing the mygemname.rb file to the engine.rb file. In short, I needed
require 'mygemname/engine' if defined?(Rails)

Resources