ruby-on-rails

How to paginate blog posts in a Rails application

I tried the following code but it doesn't work class BlogsController < ApplicationController def index #@entry_pages = Paginator.new(self, Entry.count, 10, params[:page]) @entries = Entry.find(:all, #:limit => @entry_pages.items_per_page, #:offset => @entry_pages.current.offset, :order => 'entries.created_at DESC',...

Rails validation message error?

I want to do something like this: validates_presence_of :name, :message => custom_message def custom_message "Custom Message" end But when I try it I get "undefined local variable or method for custom method" Whats up with that? ...

How much logic do you put in views?

Hi, I am currently unconfident, if I can put a "if/else"-construct into my view? How much logic do you put in your views? My dilemma: I am rendering a navigation. So, I have to differ between the current/active menu item and the rest. The current menu item gets a special css class. I don't know how to handle this in a better way than...

Authlogic run validations on login prior to create action

I need to run the built-in validations on the login field prior to actually creating the user record, is there a way to do this in Authlogic? The reason for is when a user types in a new login, AJAX is invoked to check and see that the login in unique, valid, etc. Once that is done, the user can enter his email to claim the login, it's a...

belongs_to not using primary key option

Hello, I've been struggling with this for a while, and decided to throw it out there: I have 3 models, User, Connection, Suspect A User has many Connections, A Connection has one Suspect, linked via case_id A User has many Suspects through its Connections. The code is as follows: class User < ActiveRecord::Base has_many :followe...

Ruby on rails model with multiple parents

In my Rails application, I have two models, Articles and Projects, which are both associated with a user. I want to add comments to each of these models. What's the best way to structure this? Here's my current setup: class Comment < ActiveRecord::Base belongs_to :article belongs_to :project end class Article < ActiveRecord::Base ...

Rails duplicating view

Hi, I'm trying to display all @user.notes on my index action of the user_controller, and provide a form below to add a new note, inline. Pretty simple code that I've gleaned from a few tutorials, but what's happening is my view is completely duplicated. It spits out 2 copies of the same html. Still pretty new to rails so I'm having a ...

Plugin architecture for rails cms

I'm working on a cms and wanted the ability to offer custom extentions for certain accounts. Like having a plugin with custom code that is only available or only used by that account. These custom extentions would be specific to the business needs of an account and perhaps unlikely that any other accounts would need it, but maybe. Is t...

Can Rails' Active Record handle SQL aggregate queries?

Hi, Just started learning active record and am wondering how to best retrieve data from multiple tables where an SQL aggregate query is involved. In the following example (from a medical app) I'm looking for the most recent events of various types for each patient (e.g. last visit, last labtest etc). As you can see from the sql query be...

How to tell whether you are in a rake task or not

I have a default scope set in my model. However, when I call a particular model function from my rake task, I don't want the scope to be in effect. So, when my model is loaded, how can I tell if it was loaded within a rake task or not. ...

How to post news feed in facebook from my site

Hello all, I have a site that allows a user to login using their facebook login id through a RPX system. When the user posts a comment in my site, I want it to automatically post the comment on their facebook wall too. How can I do this using Rails? I've been learning the facebooker plugin for a couple of days and still can't figure o...

Action Cache for root URL not working

Here's the setup. I have web site which is essentially a simple CMS. Here is the routes file: map.connect ':url', :controller => :pages, :action => :show map.root :controller => :pages, :action => :show, :url => "/" The page controller is thus: class PagesController < ApplicationController before_filter :verify_access, :except =>...

rails Subscribe To Comments plugin like wordpress

Is there any rails plugin for Subscribe to comments one like the Wordpress has?? i.e. On the comment form, a checkbox to check whether the commenter would opt-in whether to get email notification when a new comment is added? ...

Yaml load error in Ruby

I had this error when I do rake in the app directory, looks like YAML was failed to load. Can anybody help? Thanks C:\Development\RUBY\laibe\ilr>rake --trace (in C:/Development/RUBY/laibe/ilr) ** Invoke default (first_time) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (firs...

When I run any "rake" command, I get: uninitialized constant Gem::Specification::PLATFORM_CROSS_TARGETS [solved]

Hello, After installing RedCloth, I can not run any "rake" -tasks. I get: rake aborted! uninitialized constant Gem::Specification::PLATFORM_CROSS_TARGETS Here's output of rake routes --trace Versions: Rake - 0.8.4 Rails - 2.3.2 Ruby - 1.8.7 RedCloth - 4.2.2 Gem - 1.3.5 the Rakefile: `require(File.join(File.dirname(FILE), 'co...

What is the shortest way of inserting a variable into text with PHP?

I'm wondering if there is a shorter way of inserting text in PHP than <?php $city = "London"; ?> This website is a funky guide to <?php print $city; ?>!!! For example, using ruby on rails, I could set city = 'London' somewhere in the code, and in my .erb file I could do This website is a funky guide to <%= city %>!!! I did rea...

how to query restful rails app with curl?

here's my problem.. resource: user method: create I call curl like this: curl -X POST -H 'Content-type: text/xml' -d '<xml><login>john</login><password>123456</password></xml>' http://0.0.0.0:3000/users but the params hash in rails look like this: {"xml"=> {"login"=>"luca", "password"=>"123456"}} I want it to look like this: {"lo...

Auto-comment model on migration in Rails?

I seem to recall that there was a plugin or Rake snippet that would put comments in various Model classes after running a migration? It's a chore to have to look at db/migrate/X when I want to see which fields a given model has. If not, I'll write one, of course. :) ...

Installing Mysql gem on OSX error - 'Marshal data too short'

Getting a 'marshal data too short' error when trying to install the mysql gem on OSX. Poking around I've heard suggestions to clear out .gems, but can't seem to locate it on the system. Can anyone offer help? apple$ sudo gem install mysql --backtrace --debug Exception `NameError' at /Library/Ruby/Site/1.8/rubygems/command_manager.rb:1...

How do I hide an element before the page loads in rails?

I have a list of "li" tags and I can hide and show no problem through RJS based on user input but what the data gets saved and then the user comes back the next day, how do I make it so the page comes with the elements still hidden? In other words, based on data in a model, how do I tell an element it should be hidden? ...