ruby-on-rails

Should you only use local variables in a partial?

Using local variables seems advisable in a partial that could be used application-wide to avoid dependencies across the application. But within a single controller it seems acceptable to reference instance variables that you know will be available in all of the actions that use the partial. If you do this, there seems to be a risk, h...

Rails dashboard design: one controller action per div

I am implementing a dashboard as a relative Rails newbie (more of an infrastructure guy). The dashboard will consist of multiple pages, each page of which will contain multiple charts/tables/etc. For modularity, I want it to be as easy as possible to add new charts or change views of the data. Say one page has 5 different charts. I c...

are cookies mandatory for Ruby on Rails app?

is it true that Rails depend on cookies? It seems that flash is a part of session, and session uses cookies... so when i disable cookie in Firefox, a Rails app that was working shows [error] ActionController::InvalidAuthenticityToken so is it true that for a RoR app to work, cookies are mandatory? Update: or, to make the Rails ...

Authlogic working via curl but not browser

This probably has as much to do with rails as authlogic, but I am pretty stuck. If I use curl to request a url as follows: curl http://neevor:l3ftcas3@localhost:3000/users/alerts/1.xml I get the desired result. However if I try to do the same using a browser I get: Redirected to http://192.168.0.49:3000/login Filter chain halted as [...

Variable field name in named_scope?

In a Rails model I am trying to acheive a named_scope that filters on a start_date and end_date. This is easy. But I am going to have to do it on lots of different fields on many occasions. Is this asking for trouble? If so why (SQL injection?) and is there another way to acheive this. named_scope :between, lambda {|start_date, end_da...

Rails combined ('AND') searches on associated join tables

I cant get rails to return combined ('AND') searches on associated join tables of an Object. E.g. I have Books that are in Categories. Lets say: Book 1: is in category 5 and 8 But I cant get 'AND' to filter results using the join table? E.g ::-> Class Books has_and_belongs_to_many :categories, :join_table => "book_categories" Book.fi...

Rails Enumerated Types or Alternatives

I'm just learning ruby on rails and I have a table of user roles (Owner, Admin, and User). There are going to be places in the code where I need to check the user's role and show different options. Does anyone know how to do this without resorting to magic numbers or other ugly methods? In ASP.Net web apps I've worked on I've seen thi...

on Rails, how does form_for and validate_presence_of work hand in hand?

when we have validate_presence_of :name in the model and then when we put in the create action that we re-render 'new', then the form_for will populate the fields, and error_messages_for 'story' will have the correct error message. this is really great, and and the same time, this looks like magic... i found that many books don't explai...

First request to Rails app is very slow

Hello, always the first request (of a working session) to my Rails app is lagging. Switching to production mode doesn't help. I use mongrel and the other requests are handled with acceptable speed. How do I make it faster? Regards ...

Gems and Ubuntu 9.04

Hi, I recently upgraded to Ubuntu 9.04 and I have issues using gems. I have installed ruby, ruby gems and rails using apt-get The rails command do work. I have then installed capistrano and other gems (such as heroku). In order to do that, I have used the command sudo gem install XXX When I want to use the cap command it does not w...

rails flash graph/chart plugin

Hi, I am looking for a rails flash graph/chart plugin, for drawing bar chart, stacked bar chart, pie chart, stacked area chart, and line graphs which support the below criteria, 1. Customizable tool tip. For eg: when i am drawing a stacked area graph, i want to display all the y axix values for that x axis point as tool tip. 2. Graph ...

What's the easiest way to find the join model given two entities when using has_many :through

I'm using has_many :through to specify a many-to-many association between two entities and I want to be able to retrieve the model from the join table easily. Here are the main entities: class Group < ActiveRecord::Base has_many :memberships has_many :members, :through => :memberships end class Member < ActiveRecord::Base ...

Rails: Validate that all fields in a date_select were selected but still set :prompt to true

When using Rails date_select with :prompt => true I see some very strange behavior when submitting the form without all fields selected. Eg. Submitting the form with January selected but the day and year fields left at the default prompt results in January 1st 0001 getting passed to the model validation. If validation fails and the for...

blinking Images

i have dynamic images from a database...i want to have a couple of images on top of each other..like a banner ad, when one image fades the other one displays... When you click on the image it should redirect to a specific link ...

Minus Percent Greater-Than vs Percent Greater-Than (i.e. -%> vs %>)

I'm new to Ruby on Rails and am working my way through the tutorial posted here: http://www.tutorialspoint.com/ruby-on-rails/index.htm One of the questions I have is that I see this used sparingly throughout the code samples: <%= link_to c.title, {:action => 'show', :id => c.id} -%> Where other times, I see this: <%= link_to 'Edit',...

How to render different partials depending on current locale

I got index.erb and index-de.erb, and somewhere I saw an example where this resulted in index-de being rendered when I18n.locale was :de, but i just tried and it did not work and I could not find any documentation on this subject. So does this actually work or do I need an extra plugin for this ? ...

Amazon-ecs how to get the product's top level category?

I'm using the amazon-ecs gem to get product details from Amazon, using the itemlookup function (passing the ASIN). While I'm able to get all product details from this function, I'm not sure how to get the product's top level category - for example, if I have a children's book, I want the category as 'book' not fiction or children's book...

SVN Weirdness: Is It Possible It's Not My Fault

(I don't really care if it's my fault but rather why things are happening, of course...) I have a rails site in SVN on a remote server. On my local copy I do a switch (svn switch http://whatever/branch .), and then things are totally bizarre and the site doesn't work. I finally track it down and it turns out that part of the build (part...

Where is this Rails file stored? db/development.sqlite3

I'm trying to find the sqlite database file that rails creates. Sorry if this is a dumb question but which folder is this file stored in? I've looked in all of the folders in my Rails project and can't find it. My database.yml: development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout...

attachment_fu: Don't reload thumbnails

Hi, I've got a nice little "photos" class that has attached images. When I go to the page to sort the photos' order, it iterates though each photo, sets the new "sort" value, and saves it. All good so far. Problem is, I've noticed this behavior is fairly slow. Turns out, attachment_fu reloads the thumbnail on every save - regardless of...