ruby-on-rails

Starting Ruby on Rails from an Objective-C background

Hi, Right now I program exclusively with Objective-C using the Cocoa frameworks to write applications for the Mac OS X and iPhone/iPad platforms. I'm fairly fluent using the Objective-C language as well as the Cocoa and Cocoa Touch frameworks. I also know just enough C to be able to understand ObjC. One of my projects requires that I ...

What's best here, Rails Association Scopes or Just SQL?

I'm not quite sure what to do here, here's the situation: Given these models... class Post < ActiveRecord::Base has_many :post_assets has_many :assets, :through => :post_assets acts_as_scopeable :assets, :scopes => [:featured] end class PostAssets < ActiveRecord::Base belongs_to :post belongs_to :asset # context is so we...

combine 2 operations in if confition

I currently have: if @message.save @message.deliver_contact flash[:success] = t('Your_message_successfully_sent') redirect_to root_url else render :action => 'new' end In this code a message is first saved in the database and afterwards sent out (@message.deliver_contact). But, if the delivering fails, the record was already ...

Ecommerce Gems for ROR?

I'm working as a project manager on a site with an Etsy-like shopping cart setup (allowing users to sell their products and taking a small percentage of the sale). While I expect my developer to answer this question, I figure it can't hurt to ask if anyone recommends specific gems for such a shopping set-up in RoR or financial reporting....

Rails: load_paths for directory and all subdirectories

In environment.rb I can add the line config.load_paths += %W( #{RAILS_ROOT}/app/models/foos ) where 'foos' is a folder. This loads all files inside the foos folder. However it doesn't load any of its subdirectories. If I knew the names of all the subdirectories in the 'foos' folder, this problem would have an easy solution: %W[fold...

Deploy a subdirectory to Heroku

I have one 'super' repository in GitHub which will contain several applications I would like to deploy to Heroku. Here is an example of my repository. /app /.git /website <-- would like to deploy this to Heroku When I try to push using the following command: $ git push heroku master I get the following error: Heroku push rejec...

script/console won't work; reports "Missing the Rails gem. Please `gem install -v= rails`..." even though rails shows as installed

I'm trying to learn RoR, and running script/console fails, returning: Loading development environment (Rails 2.3.5) Missing the Rails gem. Please gem install -v= rails, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version i...

Rails has_many :through and Setting Property on Join model

Similar to this question, how do I set a property on the join model just before save in this context? class Post < ActiveRecord::Base has_many :post_assets has_many :assets, :through => :post_assets has_many :featured_images, :through => :post_assets, :class_name => "Asset", :source => :asset, :conditions => ['post_assets.context ...

will_paginate produces escaped html in rails3, raw and .html_safe do not seem to help.

will_paginate produces escaped html, what am I missing here. I've verified that will_paginate producted html_save code, I've tried adding will_paginate(@pictures).html_safe as well. Note that page_entries_info works as it should, its just the main helper that is messed up. For the time being I've done the code manually, but for obviou...

Error with "to_sql" on Rails 3 Beta 4

I'm testing Rails 3 beta 4 on Ruby 1.9.2-head, and when I start a console and do: Game.first.to_sql I get this error: ArgumentError: wrong number of arguments (0 for 1) I know it can find the Game record, because when I type: Game.first it returns: => #<Game id: 1, name: "Galaga", created_at: "2010-06-19 11:02:37", updated_at: ...

How to use Delayed::Job in an after_save callback?

I want to run the method process_images asynchronously after_save with Delayed::Job. However, when I try: after_save lambda { send_later(:process_images) } I get a NoMethodError: You have a nil object when you didn't expect it!. (self.send_later(:process_images) work either) ...

using javascript in a rails view when a link is clicked

Hi, I'm a full on newbie at programming. I know what I'd like to do, and believe I have the code I need, but I don't know how to get everything hooked up. I have this link: <%= link_to 'Start monitoring this room', start_robot_path(@robot), :style => "color:green;" %> When it is clicked/pressed, I would like this javascript co...

Making the part of rails app available(which doesnt require db) when the database goes down.

I have a Rails app whose major part is to query another web-service using ActiveResource and show the results to the users. But it uses the database for other features like user-login , reviews comments etc. When the mysql database goes down , the whole app goes down. In such cases i want have atleast the part which doesnt requir...

File upload to a specific folder

I am using attachment_fu for file uploading... it saves the files to asset/0000/0001... something like this... i want to upload a file to a specific folder defined by a user... for example images to a specific folder... just like galleries... how will i achieve this... help me out here... thankx take care.. ...

How to load the data from a .yml file to database?

There is a table questions, and a data file questions.yml. Assume there is no 'Question' model. 'questions.yml' has some recodes dump from the table. --- questions_001: title: ttt1 content: ccc1 questions_002: title: ttt2 content: ccc2 I want to load the data from the yml file, insert them to database. But I can't use rake db...

Ruby and MongoDB: Traversing arbitrary BSON document retrieved from mongomapper

In Ruby, how can I traverse an arbitrary document retrieved from a collection using something like mongomapper? Let's say the document looks something like this: mydocs = [{"title":"my title", "description":"hello world", "comments":[{"user":"me","text":"this"},{"user":"him","text":"that"}] }, {.....} ] ...

Whats the meaning of :slug in route.rb (ruby on rails). How its mapped?

Whats the meaning of :slug in routes.rb (ruby on rails). How its mapped? ...

How to get a list of online users in Authlogic?

Hey, I've added a last_request_at field to my user table in Ruby on Rails, so now I can call the authlogic method User.logged_in.count and it returns the correct value. But how do I get a list of all logged in users? Thanks for reading. ...

Is there any gem can dump the data from and to yml files?

I'm find such a gem a whole day, but not find a good one. I want to write one, but I'm not able to do it. The data in my database may be English text, which will be dump to a yml file with plain text. And some are non-English text, which will be binary type. And both of them may have such code: <% xxx %> When I use rake db:fixtures:...

Routing IN RUBY on RAILS

So for example, if I give like this map.root :controller => "pages", :action => 'show', :slug => "**homepage**" map.connect '*slug', :controller => 'pages', :action => 'show' what will happen? ...