ruby-on-rails

Clearing out session data in a Rails application

I find it odd that rails doesn't have a standard way of clearing out old sessions (file, ActiveRecord, or otherwise). There's a rake task that deletes all of them, which is not what I need (need to only delete sessions older than X weeks). I can write a 3-line script and run it periodically easily enough, but wanted to first check if th...

How to make the view simpler, the controller more useful?

This question relates to cleaning up the view and giving the controller more of the work. I have many cases in my project where I have nested variables being displayed in my view. For example: # controller @customers = Customer.find_all_by_active(true) render :layout => 'forms' # view <% @customers.each do |c| %> <%= c.name %> <% ...

Best way to implement calendar/event program in RoR?

Hi, I need a way of implementing a calendar for a webpage to show events this month for a local society i am a member of. I am looking at doing this project in RoR. But have no experience of calendars in RoR can any one recommend any good plugins for RoR for me to play with? Thanks in Advance Dean ...

capistrano unknown database

hi, I tried deploy ror app using capistrano. when i ran the command 'cap deploy:migrations", i got the following errors: Missing these requried gems: rake aborted! Unknown database 'hylog_production' do i have to resetup the databases manually on production server? ...

Working on my first json from scratch and I can't seem to figure this simple part out..

HAML: = link_to 'redeem', redeem_admin_organization_path(organization), :class => 'button_short live redeem' Controller: def redeem @organization = Organization.find(params[:id]) @organization.update_attribute('accumulated_credits', '0') end redeem.js.haml: == $("#organization_#{@organization.id} .redeem").html("#{escape_javas...

Debugging Rails application with Textmate

How do you guys debug your Rails apps? I have seen a link to datanoise.com that is supposed to show how to use ruby-debug with Textmate using a bundle.. but it looks like the page is down. Does anyone know how to set this up? Thanks! ...

Error when following RoR Video

Hi, I keep getting this error compile error /Users/dean/src/carolian/app/views/layouts/events.html.erb:10: syntax error, unexpected ',', expecting ')' /Users/dean/src/carolian/app/views/layouts/events.html.erb:11: syntax error, unexpected ',', expecting ')' "jquery-ui-1.8.2.min", "application").to_s); @output... I have followed this rail...

Rails 2 - partials: what does @comment = Comment.new mean?

I am working through a tutorial with the following code: <h3>New Comment</h3> <%= render :partial => @comment = Comment.new, :locals => { :button_name => "Create" } %> I believe that 'render :partial => @comment' works like 'render :partial => "comment", :object => @comment' Where does ' = Comment.new' fit in? Is it shorthand f...

HAML White space removal only on the "inside lines" within a loop (Ruby on Rails)

To generate <span> or inline elements using a loop, so that the result has no white space between them: %div - 5.times do %span> hello the above will create <div><span>hello</span><span>hello</span><span>hello</span><span>hello</span><span>hello</span></div> (practically, it is no use to stick "hello" together, but say, if we...

jquery ui tabs ajax load in rails

Hi, I am using jquery ui in a rails application. I want to load content of the tab via ajax when the tab is clicked. I have evverything set up correctly, i.e. my controller responds to a xhr request and it simply replaces the content of a certain div (inside the tab content). This all seems to work fine with prototype, however, If I try...

Load Ruby on Rails partial into jQuery UI dialog

Does anyone know how I can load a Ruby on Rails partial into a jquery dialog? I want to do something like this $('#advancedExerciseSearchLink').click(function() { $('#advancedSearch').load('/path/to/advancedsearchform_partial').dialog('show'); } I could pre-load the partial on the parent page and just show it when the advanced sear...

MongoMapper - Updating existing records with new keys

When adding a key to an existing model (with existing data) via MongoMapper, I can create new documents with the new key but when trying to access existing documents using that same key it fails stating that it's an "undefined method." I was wondering if anyone had any insight. Thanks in advance! (Yes, these examples are truncated.) ...

How do I have different paperclip paths set depending on whether in development or production in rails?

I am using Heroku for my production environment so I need to load the paperclip files into different directories. For development I want it to continue in the current /system default, and in production I want to pass the :path variable to a /tmp directory per Heroku. How do I do this? Am guessing maybe set something in the environment...

Converting filesize string to kilobyte equivalent in Rails

Hello, My objective is to convert form input, like "100 megabytes" or "1 gigabyte", and converts it to a filesize in kilobytes I can store in the database. Currently, I have this: def quota_convert @regex = /([0-9]+) (.*)s/ @sizes = %w{kilobyte megabyte gigabyte} m = self.quota.match(@regex) if @sizes.include? m[2] eval("se...

Which is faster to learn: Django (Python) or Ruby on Rails (Ruby)?

I have done the front-end of my design, but I have no experience in web programming. Would like to pick up a language asap so that I can deploy the product. Which is faster to pick up between the two? I know there is always debate in which is better. I think either one serves well for me, but I want to know which one is easier to learn, ...

Query for all rows with created_at between certain hours?

I need to retrieve all rows from a table where the created_at timestamp is during a certain hour ... say 04:00 and 05:00. Anyone know how to do this? ...

Using polymorphic paths with nested associations.

I have a polymorphic association that looks like this: class Line < ActiveRecord::Base belongs_to :item, :polymorphic => true end class Education < ActiveRecord::base has_many :lines, :as => :item end class Work < ActiveRecord::base has_mayn :lines, :as => :item end I'd like a simple way to create a new Line from the parent...

How do i parse the XML document in the callback?

I get back the responseXml as a javascript object XMLdocument. How do i parse it to just return the body? here is my code snippet: goog.net.XhrIo.send("/blogs/create?authenticity_token="+ goog.string.urlEncode(authtoken), function(e) { var xhr = /** @type {goog.net.XhrIo} */ (e.target); var responseXml = xhr...

SizeOf function

I want to get the number of bytes occupied by a variable or type in Ruby. Is there an equivalent SizeOf() function in Ruby on Rails? ...

Named_scope at least one in has_many association

I have a User model that has_many :posts. If I wanted to make a named_scope for finding users with at least one post would this be correct? named_scope :at_least_one_post, :joins => :posts, :group => "users.id" or should I take it a step further and do named_scope :at_least_one_post, :joins => :posts, :group => "users.id", :hav...