ruby-on-rails

The Authlogic record method. What does this do

I came across this method called record that Ryan bates uses in his authlogic Railscast and can't seem to understand what it does. I have been through the documentation but I can't seem to follow how that helper is useful. def current_user return @current_user if defined?(@current_user) current_user_session && current_user_session....

compare operators

How do I Create a webpage using JavaScript that takes a number from the user and compares it against three ranges of numbers, unsing 3 functions, checklow(), checkmedium() and checkhigh()? ...

What is a good way to assign a model object to a symbol after saving it?

How do I return the object after a model save like: Message.new(:receiver => receiver, :sender => self, :subject => subject, :body => body).save I understand I could probably do a Message.last But will there be any implications during a high traffic time period where the database is constantly being access...

Adding wordpress Blog in a Rails application

Hey, I have Rails application deployed on my home root directory of a domain and symlinked with my public_html/applicationname.com/. I wanted to install wordpress in applicationname.com/blog path. But rails ain`t allowing me to do so. I have tried a subdomain as well, but still, the routes are being handled by Rails. What would be the ...

variable from controller into view in rails?

I know this might be a dumb question. I'm trying to use this xml parser http://nokogiri.rubyforge.org/nokogiri/Nokogiri.html I've put the code below in a controller in a bringRSS method(?), and it works fine in IRB. But how do I get values for puts link.content into my views def bringRSS require 'nokogiri' require 'open-uri' ...

How to find the local port a rails instance is running on?

So I would like my Rails app instances to register themselves on a "I'm up" kind of thing I'm playing with, and I'd like it to be able to mention what local port it's running on. I can't seem to find how to do it - in fact just finding out its IP is tricky and needs a bit of a hack. But no problem, I have the IP - but how can I find wha...

Queries or methods in Rails?

Hello. I'm creating a Rails app and would like to know which of these is better: Store default data, like categories names, in a DB and get the data with queries; or create a method in ApplicationController that, with the category_id as argument, returns info about the desired category? Obs: The values will rarely be changed. Thank...

Non-CRUD Controller Actions

Hi All, This might seem like a n00b question, but I am trying to break some of my bad practice that I may have adopted using MVC, so I hope you can help me out So, imagine I want to do something like "Upload CSV And Parse It", it doesn't seem obvious to me to fit it into the CRUD pattern... I am not interacting with the DB, so i don't ...

Validating a Rails model post-save?

I have a model with a couple of accepts_nested_attributes_for. There is a requirement that I have at least one of each of the nested attributes when saving and moving on. However, validation occurs pre-save, so when I'm removing an item and moving on, it let's it through. How can I validate that when I've saved, I have at least one it...

How to handle validation with has_many relationship

class Article < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :article validates_presence_of :body validates_presence_of :author_name end If I leave the author_name as blank then I am getting proper validation error. All good. >> Article.first.comments.create(:body => 'dummy body')...

How to determine if a Rails object is marked_for_destruction?

I have some objects which happen to be nested_attributes of something else. When they are marked to be deleted, Rails creates a property "marked_for_destruction". How do I read this var? Sample Yaml dump: --- &id001 !ruby/object:LineItem attributes: name:Pay created_at: 2009-10-12 16:30:51 updated_at: 2009-10-12 16:30:51 stat...

Site wide redirect

I created a new website, hosted with Heroku, about 3 weeks ago and have since decided I wanted to change its domain name. I was trying to figure out how to do a site wide redirect and I'm thinking of going with something like in my application controller (add a before filter): def new_domain redirect_to url_for(:controller => params[:...

Loading message and test results appears after running rake task in Rails application

The following output appears after running some rake tasks: Loaded suite /usr/bin/rake Started Finished in 0.00042 seconds. 0 tests, 0 assertions, 0 failures, 0 errors This output is not useful or necessary for tasks not related to testing. I'd like to prevent it from appearing. I would assume it stems from requiring a certain file ...

authlogic crashes with infinite recursion

Hello, I have some trouble with using authlogic in my rails app, so I began using the blank example from github.com/binarylogic/authlogic_example which doesn't work either. I spent a day installing ruby 1.9.1 and 1.8 and jruby1.8, neither did work. The fun thing is that another rails app worked on my server. That said, I just cannot se...

Which are the precious Rails RubyGems that Railers can't live without?

There are a lot of interesting gems beyond the classic Rails gem pack: cucumber, formtastic, rspec, shoulda, coulda, webrat, selenium, will_paginate, authlogic, searchlogic, inherited resources ... Let's make some effort to catalog the best Rails gems on SO. I'm new to the Rails community and a little bit lost with so many options for ...

Select, group and sum results from database

Hello I have a database with some fields I'd like to sum. But that's not the big problem, I want to group those fields by the month they were created. ActiveRecord automaticaly created a field named "created_at". So my question; how can I group the result by month, then sum the fields for each month? Updated with code @hours = Hour.al...

Rails: Passing multiple parameters to form_for url?

This works great: - form_for @user, :url => { :action => :create, :type => @type } do |f| ... Returns /users/(id)?type=type But in another view I need to pass TWO parameters into the URL string, and this does not work: - form_for @user, :url => { :action => :update, :type => @type, :this => @currently_editing } do |f| ... Returns ...

How to get at the underlying object inside a Rails form or field_for block?

I can't figure-out how to get at the underlying object in a form_for or field_for block. What I'd like to do is something like: <% f.fields_for :children do |child_form| %> <%= render :partial => "#{child_form.underlying_object.class.name.downcase}" %> <% end %> and :children is a polymorphic has_many association. Suggestions? ...

Deploying rails application to multiple environments

I am getting ready to deploy to a true production environment. When I say true I mean that my current production environment will now be staging because there is other crap on the server and I am creating a new larger slice for what will actually be my production machine. The capistrano-ext gem has made separating the deploy recipes qu...

Render partial from another model

Hi everyone, I have a rails application that models a house. There is a house model that has many parameters and it has_many rooms. A room has a house_id and a name. I've also used http://github.com/ryanb/complex-form-examples to allow many lights and small_appliances to be added to room. complex-form-example uses RJS and partials to...