ruby-on-rails

Rails timezone is wrong when shown

I have a problem when showing a datetime object from the database. The time is correctly set in when storing the object, but when it is fetched from db and shown to user it is shown in UTC environment.rb config.time_zone = 'Copenhagen' This is what is saved using Time.now or Time.zone.now 2010-07-08 13:59:50 +0200 This is what is s...

How do I add custom javascript to my rails3 views?

What is the best way to add JavaScript to my Rails3 views? I would like to be able to do some processing in a controller, then craft some JavaScript based on the result and put the resulting JavaScript in a view. For example, I would like to get a series of lat/lng points from a database and create markers on a Google Map. The map i...

What is this "_ifbk" constraint doing in my table?

I'm working on a Rails web application with a MySQL database. I'm using migrations to modify the schema. I've just run into a problem wherein I'm getting an invalid record error on inserting a new record. The relevant tables: users id | name | email | ... academic_records id | scholar_id | gpa | ... academic_records.scholar_id is a ...

What's the correct way to read some data from a yaml file and use it in an erb page?

I'm using rails to build a website. I have a yaml file contails some colors, which is config/colors.yml --- - white - red - blue - yellow - ... And, there is an erb file app/views/users/setting.html.erb, which will need the data in config/colors.yml, and put them in a tag. I don't know what's the correct way to read the yaml file. ...

Memory Leak with Ruby 1.9.2 Rails 3.0 Beta 4

I have tried various combinations and find that by simply generating a skeleton Rails 3.0 application, and then running siege http://localhost:3000 My ruby process would then leak a few MB every 5 minutes. The reason I tried this is because I just converted a full blown Rails 2.3 and Ruby Enterprise 1.8.6 application over to Ruby 1.9....

How to name Many-To-Many association? [ActiveRecord]

I have a model called Purchase and a model called TicketType. A purchase can have many ticket types, and a ticket type can have many purchases. So I have class Purchase < ActiveRecord::Base has_many :purchases_ticket_types, :class_name => 'PurchaseTicketType' has_many :ticket_types, :through => :purchases_ticket_types end class T...

how to select n random rows in mysql from subset of large table?

I know there is this question that is very similar, but I wanted to add my specific situation and see if the answer is different. I've read that you can simply do ORDER BY RAND() but that that is a bad idea for large tables. However, I can limit my rows to a max of about 160 with the WHERE clause. So the question is, is the WHERE clause...

How to host Redmine on Dreamhost?

I was able to install redmine on dreamhost without any problems. I followed the directions from the dreamhost wiki and it is up and running. The problem is that it is very slow. So slow that it errors out sometimes. It gives a pipe broken error. Is there anything that can be done to improve the performance and eliminate the broken pipe e...

HTTP Basic Authentication with Authlogic

I'm trying to get http basic authentication working on my rails app. I am running the app with nginx and passenger. I have the authlogic gem working and my authentication works. I have even used the single_access_token successfully. For some reason though, I am not able to authenticate using http basic authentication. As I understand, I ...

cascading drop down box implementation without ajax in ruby on rails

I am newbie in RoR and creating my first project. I have two models category and article.category has many article and article belongs to one category.I want to create cascading drop down boxes to display article.In first drop down box I want to select category which update second drop down box with articles which belong to the category....

Sharing a session between Node.js app and Rails app

I'm running a Rails app on Heroku, and I'm trying to port over all inline Twitter requests (namely oauth authentication) to a Node.js app, because when Twitter is slow, since the Ruby server is blocking, the Twitter requests clog up my app. (My average request takes about 50ms, but my average Twitter Oauth request takes about 1500ms!) T...

Copying cookies from main domain to subdomain

My application has a userspace which used to be accessed by a url like domain.com/~username, but I am in the process of converting that to using subdomains instead (username.domain.com). However, I am running into an issue that I'm hoping someone might have an idea of how to get around. Currently, visitors to a user's site get a cookie ...

Any lazy way to do authentication on RoR?

I want to make a simple login, logout, also, different user have different user role. The Restful authentication seems works great, and the cancan is also very sweet for controlling user ability. But the question is how can I let these two works together. I watched the railcast, I was whether how to detect the user ability? Do I need to ...

when is a pessimistic lock released in rails?

Assuming I'm doing something like this (from the Active Record Querying guide) Item.transaction do i = Item.first(:lock => true) i.name = 'Jones' i.save end Is the lock automatically released at the end of the transaction? I've looked at the Active Query guide and the ActiveRecord::Locking::Pessimistic docs, and couldn't...

Get an asset's numerical position in an array in Ruby on Rails

Hi All, I'm working with a list of assets, sorted alphabetically (through another method). I would like to assign a value to the "position" key, which essentially just says where this particular asset appears in the ordered list of all assets. Here is the code I'm working with now (:position left blank on purpose): @active_resources.ea...

Plugin for static code analysis of Rails app

Hi, I want to run a static code analysis over my Rails app. Is there a tool available that can help me do this? Thanks, Sivakumar. ...

rails: authlogic passing a session parameter to UserSession.find

I'm passing the user session via a parameter (params['session_key']) for one controller (it's a flash upload script so I have to pass it via a param). I don't know how to access the user session with authlogic by using the raw param string. Normally I do this: @current_user_session = UserSession.find I thought I could do this: @cur...

Ruby on Rails: In there a way to convert word to html?

maybe a way to batch convert also? ...

Custom to_json method not being called in Rails app

I have a Ruby on Rails application that I'm working on an API for an associated iPhone application. I have overwritten the to_json method of my Item model to return some custom information from the API request that I'll need in the iPhone app. However, when I use the built-in rails to_json method and include my Item model as an associa...

Rails Polymorphic Model. How to show form validation erros on views?

I have everything on my polymorphic associations working, but if I have model validations, the erros don't show up. In my controller I have: def create @locatable = find_locatable @geographic_location = @locatable.geographic_locations.build(params[:geographic_location]) if @geographic_location.save flash[:notice] =...