ruby-on-rails

Can I restrict Rails controller methods to development environment?

I have a Rails application that generates a weekly report and emails it out. I don't want the production app to have any sort of web interface, for security and convenience reasons (don't want to maintain a web interface). However, I do have a rudimentary web interface to the database that I'd like to keep available in my development...

How can Rails' Activerecord table refer to itself?

Hello, everyone. I have an idea to use Activerecord to implement something strange like the example below: SystemInfo < ActiveRecord::Base belongs_to :SystemInfo end The idea is, System A can contain System B as its child. So I will generate application's skeleton as: script/generate scaffold SystemInfo parent_id:integer name:str...

Use find to initialize a constant?

Something like this: class Category SOME_CATEGORY = find_by_name("some category") end Category::SOME_CATEGORY tried without a problem, but want to know if it is a bad idea, and the reasons if any.. thanks ...

RoR Catch Exception on Application Level

For a specific role (group of users) I added the :readonly to every find on the active record def self.find(*args) if User.current_user.has_role? 'i_can_only_read' with_scope({:find => {:readonly => true}}) do result = super *args end end end Of course it raises now ActiveRecord::ReadOnlyRecord...

Seeing "Error: Rake tasks fetching failed with..." Under NetBeans?

Netbeans seems to be throwing this error: "Error: Rake tasks fetching failed with..." whenever I start it up, though otherwise it's fine. What does this mean? ...

has_one relationship validation in rails

Since has_one doesn't provide a before_add callback to allow validation, how do I prevent rails from destroying the old association even when the new one does'nt pass validation? susan :has_one :shirt shirt :belongs_to :susan susan.shirt = a_nice_shirt this destroys whatever association was present beforehand, even if the new shirt is...

What do I do if I don't have root access to do a gem install mysql?

Every time I run rake db:create, I get the notice that I have to run "sudo gem install mysql", but I do not have root access and the tech support is telling me that they cannot do that for me since it is on a shared server. Is there any work around about this? I do not have the option of changing hosting as of right now. ...

Exception notifier plugin not sending emails

Trying to get Rails exception notifier plugin working. I've installed it in my app... script/plugin install git://github.com/rails/exception_notification.git Put this at the end of environment.rb outside of the Rails::Initializer call... ExceptionNotifier.exception_recipients = %w([email protected]) ExceptionNotifier.sender_address = %("...

Rails :include vs. :joins

This is more of a "why do things work this way" question rather than a "I don't know how to do this" question... So the gospel on pulling associated records that you know you're going to use is to use :include because you'll get a join and avoid a whole bunch of extra queries: Post.all(:include => :comments) However when you look at ...

Is there a trick to installing RMagick & ImageMagick on Ubuntu?

I keep getting Segmentation faults in the rmagick_processor.rb:52 (part of attachment_fu) while trying to run the test suite for community_engine on a fresh ruby app. I've noticed I have both librmagick-ruby and librmagic-ruby1.8 which are both ImageMagick APIs for Ruby. Should it be just one? If so which? ...

Custom thumbnails for file types with Paperclip

I'm using Paperclip with a Ruby on Rails to attach assets to a model, these assets can be any file type and currently thumbnails are only being generated if the asset is an image. I'd like to be able to display a different default image for other files, either by generating a thumbnail of the files on upload, or setting something up wit...

How to create nested objects using accepts_nested_attributes_for

I've upgraded to Rails 2.3.3 (from 2.1.x) and I'm trying to figure out the accepts_nested_attributes_for method. I can use the method to update existing nested objects, but I can't use it to create new nested objects. Given the contrived example: class Product < ActiveRecord::Base has_many :notes accepts_nested_attributes_for :not...

Caching in Rails 2.3 help

Hello, I'm using rails 2.3 for a blog app. I'm trying to get caching to work. So far, I've managed to follow along with these tutorials: http://railslab.newrelic.com/2009/01/22/page-caching I thought everything was working fine. I even managed to get a cachesweeper to work a la the next tutorial in that series. But I noticed in the dev...

Plugins/Gems/Libraries to get syntax highlighting for code in the browser?

I have a simple idea for a small web application that I'd like to build out, but it requires syntax highlighting in the same manner that Pastie does. I was wondering if anybody knew what library (jQuery, Prototype, any) was used in the frontend, and/or which (if any) plugins/gems were used in the backend. For reference, you can find an...

workling and starling not working in ruby on rails

my code is class FatWorker < Workling::Base def do_work #some code to export csv file send_data csv_string, :type => "text/csv; charset=iso-8859-1; header=present", :disposition => "attachment", :filename => "sample.csv" end end and I'm calling this in another model def export_to_csv FatWorker.asynch_do_work() ...

Connecting Id field with name field

Hi, Am having a table with quetion_id , nominees and vote_count. In which the values for question_id and nominees are prepopulated from other tables with vote_count as zero. If the users select some nominees the vote count should be incresed by one. The problem is How to connect the question_id and nominees like for this question_id th...

Using Rails' to_sentence method on deeper branches on an array

Hi folks, I want to comma separate users.names using the handy rails to_sentence method. Of course users.to_sentence isn't right # => #, #, #, # and # It looks to me like I'll either have to create an array of the names to use this method on, or give up on using the method... That said, I'm a total noob so you'll probably have some g...

Which CMS features do you need in Rails?

I am going to write a ContentManagementSystem for RubyOnRails for administration of static pages. Which features do you prefer to appear in this CMS? What do you think might be helpful for daily work? Best regards ...

How can I turn my Rails app into a plugin?

I am currently developing a cms and want to reuse the functionality in other projects. ...

InstantRails 2.0 upgrade Rails to 2.3

Hi All, I am developing with Rails on Windows versions. IR 2.0 comes with Rails 2.0. What is the correct way to upgrade the rails (and Ruby) to the latest version? Rails 2.3 Ruby 1.9 Many thanks. ...