How to replace a hash key with another key

I have a condition where, I get a hash hash = {“_id”=>”4de7140772f8be03da000018”, …..} and I want this hash as hash = {“id”=>”4de7140772f8be03da000018″, ……} P.S: I don’t know what are the keys in the hash, they are random which comes with an “_” prefix for every key and I want no underscores 12 Answers 12

Rails – How to use a Helper Inside a Controller

While I realize you are supposed to use a helper inside a view, I need a helper in my controller as I’m building a JSON object to return. It goes a little like this: def xxxxx @comments = Array.new @c_comments.each do |comment| @comments << { :id => comment.id, :content => html_format(comment.content) } end render :json … Read more

Use rvmrc or ruby-version file to set a project gemset with RVM?

I use RVM, the Ruby Version Manager to specify a Ruby version and a set of gems for each of my Rails projects. I have a .rvmrc file to automatically select a Ruby version and gemset whenever I cd into a project directory. After installing RVM 1.19.0, I get a message You are using .rvmrc, … Read more

rmagick gem install “Can’t find Magick-config”

I get the error shown below when attempting to install the rmagick gem. I am on Snowleopard 10.6 using RVM, Ruby 1.9.2-head and Rails 3.05. Responses to similar questions recommended installing ImageMagick, which I successfully did. Other suggested installing the “libmagick9-dev library”, however, I can not figure out how to do this. I’m a new … Read more

Best way to load module/class from lib folder in Rails 3?

Since the latest Rails 3 release is not auto-loading modules and classes from lib anymore, what would be the best way to load them? From github: A few changes were done in this commit: Do not autoload code in *lib* for applications (now you need to explicitly require them). This makes an application behave closer … Read more