ruby-on-rails

Shortcut for specifying an order and limit when accessing a has_many relation?

Is there a shortcut for giving a limit and order when accessing a has_many relation in an ActiveRecord model? For example, here's what I'd like to express: @user.posts(:limit => 5, :order => "title") As opposed to the longer version: Post.find(:all, :limit => 5, :order => "title", :conditions => ['user_id = ?', @user.id]) I know y...

@Rails users: have you tried web2py? Pros? Cons?

web2py to is a Python framework but shares the "convention over configuration" design that Ruby on Rails has. On the plus side it packages a lot more functionality with its s standard distribution and we claim it is faster and easier to use. Has any Rails user tried it? What is your impression? No rants please. Just technical comments...

Redirect 'myapp.com' to 'www.myapp.com' in rails without using htaccess?

Using Morph Labs' Appspace to deploy a site means no automated way to redirect 'myapp.com' to 'www.myapp.com' (and no access to .htacess). Is there an in-rails way to do this? Would I need a plugin like subdomain-fu? More specifically, I'm trying to do something like: 'myapp.com' => 'www.myapp.com' 'myapp.com/session/new' => 'www.mya...

Does it make sense to convert DB-ish queries into Rails ActiveRecord Model lingo?

mysql> desc categories; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(80) | YES | | NULL | ...

Shared file storage for a Rails Application

I have a rails app that accepts file uploads and I wanted to know the best way to have common storage between servers. Since we have a number of windows applications we have used samba in the past, but as we build pure linux apps I would like to do this the best possible way. We are expecting large amounts of data, so would need to sca...

What is the best way to set default values in ActiveRecord?

What is the best way to set default value in ActiveRecord? I see a post from Pratik that describes an ugly, complicated chunk of code: http://m.onkey.org/2007/7/24/how-to-set-default-values-in-your-model class Item < ActiveRecord::Base def initialize_with_defaults(attrs = nil, &block) initialize_without_defaults(attrs) do ...

How do I commit the restful_authentication plugin to my git repo?

How do I add a the http://github.com/technoweenie/restful-authentication/tree/master plugin to my Rails project and the commit it to the git repo ? I need it to be committed with the project. I have tried a few times but it's ignored by git. Thanks. ...

How do I pass a string to a has_many :finder_sql parameter?

In my application, a user has_many tickets. Unfortunately, the tickets table does not have a user_id: it has a user_login (it is a legacy database). I am going to change that someday, but for now this change would have too many implications. So how can I build a "user has_many :tickets" association through the login column? I tried t...

Re-Generating Scaffold

Is there any way to re-generate views from newly updated model? ...

::Base part meaning in ActiveRecord::Base

What does ::Base part mean in Person < ActiveRecord::Base class declaration? I'm new to ruby and from what I've gathered so far, Person < ActiveRecord should be used. Thank you. ...

undefined method rails question

Hello, I'm new to ruby and started to create my *nd toy app. I: Created controller 'questions' Created model 'question' Created controller action 'new' Added 'New.html.erb' file in erb file I use form_for helper and and new controller action where I instantiate @question instance variable. When I try to run this I get 'undefined met...

How to choose a single model and persist that choice?

I have a simple model called Party with a corresponding table called parties. There's also a controller with all the usual CRUD actions and so on. This model is used in a website and only one admin user is allowed to edit the parties - everyone else is allowed to call GET actions (index, show). Nothing special so far. Now I need to do t...

How do I update the contents of a placeholder with a generated image in Rails?

I have a div tag in the view that I'd like to update with a graph that I generate via Gruff. I have the following controller action which does this at the end send_data g.to_blob, :disposition=>'inline', :type=>'image/png', :filename=>'top_n.pdf' Now if I directly invoke this action, I can see the graph. (More details here if reqd.) ...

Can I set up Cascade deleting in Rails?

Hi folks, I know this is probably on the Internet somewhere but I can't find the answer here on Stackoverflow so I thought I may boost up the knowledge base here a little. I'm a newbie to Ruby and Rails but my company is getting pretty invested in it so I'm trying to get to know it in a little more detail. It's been difficult for me t...

Connecting phpMyAdmin to a MySQL server over SSL

I may be barking up the wrong tree... However, what I have is a MySQL server that accepts connections only from a client with a valid SSL cert (see this link). This works great for example with Rails. I have my database on one server, and a Rails app that connects using the client certificate. Maybe not the fastest, but it works. The co...

How do I use frozen Capistrano?

Backstory I'm on Rails 2.1 and need to freeze the Capistrano gem to my vendor folder (as my host has broken their cap gem dependencies and I want to make myself as independent as possible). On my local windows machine I've put the following my environment.rb config.gem "capistrano", :version => "2.5.2" config.gem "net-ssh", :lib => "n...

What web application framework should I use for a web gallery?

Hey guys, I need to create a photo gallery for a website running IIS 4.0 or IIS 5.0 (im not sure which). It needs to display a low resolution version of the gallery to anyone, and it must show both the low and high resolution images for "priviledged" users. So I need access priviledges, photo albums and once the site is complete, the pe...

rails routing controller action change

Hello, rails friends. I'm struggling here with a problem: I have a controller questions which has action new. Whenever I need to create new question, I'm typing /questions/new What changes to routes.rb should I make to change the URI to /questions/ask Thank you. Valve. ...

Current view file in Rails helper method

Is there some way to determine what file currently is being rendered by Rails (2.2) in a helper method. An example result would be "/sessions/new.html.erb" or something similar. I am trying to write a helper function that does something based on the file name that is being rendered, so I need a reliable way to obtain this information. I...

LDAP through Ruby or Rails

I've been attempting to hook a Rails application up to ActiveDirectory. I'll be synchronizing data about users between AD and a database, currently MySQL (but may turn into SQL Server or PostgreSQL). I've checked out activedirectory-ruby, and it looks really buggy (for a 1.0 release!?). It wraps Net::LDAP, so I tried using that instead,...