ruby-on-rails

Rails Question: Sqlite3 dll not found on windows (even the old 1.2.3 version)

I followed the suggestion here: and the gem seemed to install correctly, but when I ran rake:db:migrate from the windows command line, I got a full on pop up saying: "This application has failed to start because sqlite3.dll was not found. Re-installing the application may fix this problem" which is really weird, because normally (when ...

Authorization header in Ruby on Rails accessed with key HTTP_AUTHORIZATION instead of Authorization?

I'm hoping someone can clear something up for me. I'm using Rails 2.3.5, and I can access request headers in a controller action like this: def index if request.headers['...'] == '...' ... end end Or something similar. request.headers is an instance of ActionController::Http::Headers which appears to be a Hash. I would expect,...

Rails or Ruby method to auto wrap lines for plain text email

I am building a comment notification system in Rails and I am trying to render user provided comments in a plain text email. When I render the comment, I want to auto wrap the lines when 56 characters are reached. Obviously I don't want to split words. Is there a function in Ruby or RoR for doing this, or do I need to roll my own? Qu...

How to have nameless YAML fixtures in Rails?

Let's say we have. apple: name: apple orange: name: orange grape: name: grape Can this turn into something below? name: apple name: orange name: grape Because I have like 25 items, manually name them is really a valueless job. ...

Rails and Authlogic. Show currently logged in user

Hi, I'm a first time authlogic implementer and everything has gone smoothly, until now. I want to display the username of the person currently logged in, beside "logout" and "edit profile" links, both of which work fine. I can't figure out how to do it though. Any help is much appreciated. Thanks. ...

regular expression

Hi i have a string like this: adfsdf dsf {{sadfsdfadf {{Infobox}} musical}} jljlk }} i want eliminate all substring {{..}} and so i tried with \{\{.*\}\} this eliminates {{sadfsdfadf{{Infobox}} musical}} jljlk }} but i want eliminate {{sadfsdfadf {{Infobox}} musical}} checking the }} more near from the start of the substring How ...

has_many at two levels

I am using Rails 2.3.5. Company has many users. User has many emails addresses. Association tables are company_users and user_emails table. I want to get all the email addresses for a company. What is the most efficient way to get that? ...

ActiveScaffold complains about association

I'm using ActiveScaffold to create an Admin UI. I have two models: Post and Comments. A Post has-many Comments, and a Comment belongs-to a post. There's a validates_presences_of :text validation the Comment model. The problem is that when I create a new Post from the Admin UI without creating a new Comment in the subform, ActiveScaff...

Checking a related relationship once the instance is created

I have a schema where: Students has_and_belongs_to_many :courses has_many :grades, :dependent => :destroy has_many :assignments, :through => :grades Courses has_many :assignments, :dependent => :destroy has_and_belongs_to_many :students Assignments belongs_to :course has_many :grades, :dependent => :destroy has_many :students,...

Can I :select multiple fields (*, foo) without the extra ones being added to my instances (Instance.foo=>bar)

I'm trying to write a named scope that will order my 'Products' class based on the average 'Review' value. The basic model looks like this Product < ActiveRecord::Base has_many :reviews Review < ActiveRecord::Base belongs_to :product # integer value I've defined the following named scope on Product: named_scope :best_reviews, ...

Does ActiveRecord allow for custom types?

I have a scenario where I am trying to do a proof of concept using Rails on a legacy db2 database to get buy off that it is a viable option platform for us to use for current and future development. All of our tables have a primary key which is defined as char for bit data, which is binary. Is there any way I can define a mapper to c...

How can I get the number of instances of a value in a Rails array?

Say I have an array like this: ["white", "red", "blue", "red", "white", "green", "red", "blue", "white", "orange"] I want to go through the array and create a new array containing each individual color and the amount of times it appeared in the original array. So, in the new array it would report that "white" appeared 3 times, "blu...

Show selected name instead of ID in rails index view

So I'm a newbie at rails and I'm trying as best as I can follow tutorials that abound the web. So I have three tables. class CreateAuthors < ActiveRecord::Migration def self.up create_table :authors do |t| t.string :name t.string :email t.timestamps end end de...

Modules vs. Classes and their influence on descendants of ActiveRecord::Base

Here's a Ruby OO head scratcher for ya, brought about by this Rails scenario: class Product < ActiveRecord::Base has_many(:prices) # define private helper methods end module PrintProduct attr_accessor(:isbn) # override methods in ActiveRecord::Base end class Book < Product include PrintProduct end Product is the base cla...

Is there a Java equivalent for Ruby on Rails "url_for"?

I have written something like this pretty easily in C# (string GetUrl(new { controller = "foo", action = "bar", baz = "fnord" }), based on the existing capabilities of the XmlRouteCollection class provided by the ASP.NET MVC framework (why it isn't there out of the box is beyond me; the additional required code was trivial). I am now fac...

rails -- track number of user login

Hey guys, I'd like to track how many times a user logs in to my site which is a Rails app. Is there any other call like "created_on or updated_on" that can make a little counter in my model that tracks that kind of info? I'm using restful-authentication currently. ...

sanitize on controller

Is there anything like sanitize for controllers? thanks ...

RESTful routes in Rails for generating reports

I am working with a Rails application that uses RESTful routes for handling it's resources. I am now creating a reports controller that will generate reports in HTML, XML, CSV, etc. There will be several different reports available for generation, depending on the parameters sent to the controller. Is it overkill to use REST for this re...

Convert from wiki to html

Hi i'm using a wikipedia api for getting info from wikipedia. Is there anything for convert wiki text in html? I've tried mediacloth but i doesn't works well thanks ...

rails- Background image not showing up???

Hey guys, I'm having the weirdest problem. I created an app in .NET and everything worked fine style wise. Now that I have redone the app Rails i'm having an issue with the background image not showing up. My CSS file looks like this.. body{ background: url('/images/top-bkrnd.jpg') repeat x ; text-align:center; color:#fff; } B...