ruby-on-rails

How to get array of many_to_many assocation from array in Rails

Hello, I have the following code in Rails: @possibleMatchingOffers = SmsOffer.valid.find(:all, :conditions => {:hub_phone_no => unhndledMsg.hub_phone_no}) @matchingContact = @possibleMatchingOffers.biz_sms_reply_queues.valid.find(:all) The Error I'm getting: You have a nil object when you didn't expect it! You might have expecte...

looping over columns in rails

This is probably very easy, but I'm having a hard time figuring it out. I have a partial: <% for room in @scrape %> <tr id="page_<%= room.id %>"> <th scope="row" class="<%= cycle("spec", "specalt") -%>"><%=h room.name %></td> <td class="<%=current_cycle%>"><%=h room.day1 %></td> <td class="<%=current_cycle%>"><%=h room.da...

How to iterate ActiveRecord Attributes, including attr_accessor methods

I've looked everywhere for an elegant solution. The essential problem seems to be that ActiveRecord attributes that map to database columns are handled completely differently in ActiveRecord::Base than attr_accessor methods. I would like to do something like: model.attribute_names.each do |name| # do stuff end in a way that also i...

How to set has_many_polymorphs CRUD parameters restfully

Working on a simple example of double sided polymorphic relationships using the has_ many_ polymorphs ActiveRecord plugin. I have two classes, "cats" and "dogs", which can have "friendships" with each other, so three classes in all: "cats", "dogs" and "friendships". A cat can be friends with a dog (yes, it does happen!) and of course als...

Rails: Unit testing a before_create?

I am trying to test that a field is being generated properly by a callback, but I can't figure this one out. album.rb before_create :generate_permalink private def generate_permalink @title = album.downcase.gsub(/\W/, '_') @artist = artist.downcase.gsub(/\W/, '_') self.permalink = @artist + "-" + @title end albu...

how do i upload picture in rails ?

how do i upload picture in rails ? ...

rails session model

How can I treat important session info as if it were a model? I've started toying with it, and some of it works. But I'm not sure what I'm missing? Does anyone know a good place to start or where I can find some good examples? Also, I'm able to use the model to set session variables, but what about getting them from the model as op...

Rails: How can I update a page with new messages? via Ajax? Jquery?

I'm trying to get some better logic behind this before I start writing code. I have a model that collects new messages via a background process. (So the database gets updated every 2-3 mins with any new messages). When the user comes to their inbox, they're presented with all their current messages. This is easy for me: @user = User...

Drop down box in Rails

How do I use Rails to create a drop-down selection box? Say if I have done the query: @roles = Role.all Then how do I display a box with all the @roles.name's ? EDIT: After implementing the dropdown box. How do I make it respond to selections? Should I make a form? ...

Whiny Nils in Rails

Hey guys, So I generate my scaffold in rails, and it creates the usual CRUD files. In my View, I copy over the form found in new.html.erb and paste it over at index.html.erb, so I can create a new record from my index. When I do that, I get the following error consistently, no matter what I do. Called id for nil, which would mistaken...

Redmine doesn't work properly in Apache

I'm trying to get Redmine (a Ruby on Rails app) working. It works fine when started with ruby script/server webrick -e production, however, I'm having trouble getting it working in Apache with Passenger. Accessing http://example.com/redmine returns the Redmine home page, but clicking any link (or even adding a / to the URL) results in a...

Initializing a Module mixed in to a Model

Hi, I have this: class Bullet < ActiveRecord::Base include StagedVersionMethods ... end And this module StagedVersionMethods def initialize puts self.bullet_id end end When I create an instance of Bullet, the modules initialize method fires, but I get an ActiveRecord error: ...activerecord-2.2.2/lib/active_recor...

Problem with named fixtures

I am working with Rails 2.3 and I have the following associations: User: has_many :photos has_many :classifications Photo: belongs_to :user has_many :classifications Classification: belongs_to :user belongs_to :photo I have a fixture for each model: users.yml: tester: username: tester ... photos.yml: bianco: id...

Display last visited/seen on profile page?

In the profile page of this site StackOverflow, there is an element named "Seen: 2 hours ago" How to implement this in Rails? I googled around but couldn't find the exact piece of code!! ...

Rails redirect_to post method ?

redirect_to :controller=>'groups',:action=>'invite' but I got error because redirect_to send GET method I want to change this method to 'POST' there is no :method option in redirect_to what will I do ? Can I do this without redirect_to. Edit: I have this in groups/invite.html.erb <%= link_to "Send invite", group_members_path(:gr...

quick method to save ruby objects on command line?

I'm using Netbeans to develop my RoR project so it is managing the SQL database. How can I make quick changes (i.e. edit row-by-row) to my DB, preferably in command line? i'm thinking - changing temporary passwords and users for testing purposes. Thanks for your input! ...

Rails - Abstract/Shared Views

I have a few objects that are incredibly similar. In fact, they use STI and store all of the data in the same table in the DB. Currently, every time I add a feature or fix a bug, I have to update it in 3 different places, so I would like to DRY my code a little bit. The most common code duplication is in the views. I have seen people usi...

Using Active Record to connect to MS SQL Server 2005 on centos

I found some instructions for setting getting Rails to connect to MS SQL Server on Ubuntu here: http://stackoverflow.com/questions/721960/connecting-to-mssql-with-activerecord What RPMS would you need to get this to work on CentOS 5.3? ...

want to clean up and change unicode form fields in using rails model in a more DRY way

Currently I am using this to strip out whitespaces. class Newsletter < ActiveRecord::Base before_validation :clean_up_whitespace end def clean_up_whitespace fields_to_strip = ['title','notes'] fields_to_strip.each { |f| unless self.attributes[f].nil? self.attributes[f].strip! end } end I want to do something simi...

Difference between -%> and %> in rails

I have started some rails tutorials and noticed that some of the view code blocks are like <h1><%= @subject.name -%></h1> and other code blocks are like <h1><%= @subject.name %></h1> What is the difference between -%> and %> If you know of some good syntax references you can point me to, that would also be helpful. ...