ruby-on-rails

recognize HTTP_USER_AGENT whether its browser or facebook bot?

I've the following condition to check the user agent. if request.env['HTTP_USER_AGENT'] =~ /feedburner/i @posts = Post.recent(10) render :layout => false else redirect_to 'http://feeds.feedburner.com/MyAppFeed' end Its working fine. Now I need to check for the facebook user agent! What would be the name of facebook user agent or i...

ActiveRecord save(false) still validating model

I have a user model on which I check to make sure that the email address supplied is unique: validates_uniqueness_of :email This model acts as paranoid. On destroy, I need to remove the email address so that if the user wants to re-register, they can. For this, I have the following: before_destroy :remove_email def remove_email se...

Best Linux variant for a Ruby on Rails app?

I'm interested in setting up my own website-based game (PBBG) as a hobby. Traffic shouldn't be too much, a couple of dozen users at a time on average. From all the reviews I've seen, Ruby on Rails is the best way to go as far as coding and platform. As far as OS goes, I've only used Ubuntu in the past and, while it worked smoothly, I ...

Is it possible and/or advisable to generate tests dynamically in rails?

One trick I have found very handy in rails application programming is that class_eval can be used to create methods on the fly. I'm starting to get into testing now and I wonder if a similar idea could be used to generate tests. For example, I have a before_filter to require a user to be logged in for all of the actions in a controller...

RoR and RSpec: How to access controller instance variables without defining accessors?

I'm writing a rspec tests for my controller and i cannot find solution following problem. For one of the edge case tests I need to verify the value of one instance variable. How can i access it without having to define the accessor? By default the usual: controller.variable.should == '3.15' doesn't work. Defining attr_reader :...

How to generate a model with a enum type field ?

I want to generate a model and the corresponding database table in rails using the generator script. The database table has a field with "enum" type. How can I generate it? The table: create table works { id int unsigned not null auto_increment, nickname varchar(20) not null, sex enum('m', 'f'> not null }; the command: script/gen...

Cucumber default_url_options[:host] everytime "www.example.com" even if specified in environtemnts/test.rb

Hello, I specified the default_url_options in my environments/test.rb with config.action_mailer.default_url_options = { :host => "www.xyu.at" } This is quite ok and in my cucumber story, where i test registration of users, the user-activation link gets generated right invitation_activation_url(1) => "www.xyu.at/signup/1231hj23jh23" ...

Should I use passenger on Apache or Nginx?

What are the pros and cons between deploying passenger on top of Apache and Nginx? ...

JRuby on Rails and calendar_date_select

Anyone have any success with a JRuby on Rails war deployment and calendar_date_select? The gem wouldn't include the helper functions and I would receive the following error since the function wasn't declared in the app: undefined method 'calendar_date_select_includes' for #<ActionView::Base:0xbe823> After installing calendar_date_sele...

What is the best way to get a temporary directory in Ruby on Rails?

What is the best way to get a temporary directory(with nothing in it) using Ruby on Rails? I need the API to be cross-platform compatible, so something like this won't work. ...

Simplest way to define a route that returns a 404.

Hi, I've got a requirement to specify a named route in a Ruby on Rails project that returns the public/404.html page along with the 404 server response code. Leaving it blank is not an option, please don't question why, it just is :) It absolutely must be a named route, or a map.connect entry would do. Something like this would be g...

Mass assign for attr_accessible :association_attributes in special cases

In the User model I have two accepts_nested_attributes_for: :details (which is has_one association) and :membership_orders (has_many). For :details I have: attr_accessible :details_attributes But for the membership_orders I can't have so simple accessor, because I want to protect it from the normal user, but make it accessible for th...

Find HTML verb for actions in rails

Is there a way to look up the HTML for a given controller action? For example, I would like to be able to associate GET with index and PUT with update. I want to be able to do this dynamically based on the routes. I can get the action methods for each controller using Controller.action_methods, but this returns a set of strings of acti...

Create new row after saving a record

A user submits a url, this is put into into article.url through the scaffold create method. I can parse the url like so: def parse_url elements = @article.url.split("/") if(elements[0] == "http:") @home = elements[2] #elements[1] will be an empty string because of the // in the URL else @home = elements[0] end end Wh...

Fancy groupings with Thinking Sphinx

I have tables boards, users, joins, and roles. The joins table defines the association a user has to a board, as well as the role that user has on that board. I'm trying to either get all of a user's boards at once with a way to differentiate what role a user has on each board, or make three separate calls to get boards that a user is a ...

Ruby on Rails HTML-Table Generator

I am looking for a good RoR table generator (or an easy solution) that can give me a decent view of my records in a table (unstylized but proper strict XHTML). Let's say I have a User model and an Address model: - A User can have many Addresses - One address is also linked as the "primary_address" Let's say I have the following in my...

Cascading Rails Loop Not Displaying Correct Data

I have the following code in my layout file: <% @families = ProductFamily.find(:all, :include => :products) %> <% @families.each do |f| %> <h2><%=h f.name %></h2> <ul> <% f.products.each do |product| %> <li><%=h product.name %></li> <% end %> </ul> <% end %> Two things: I doubt this follows standard MVC pr...

Securing REST and JSON

I want to build my web services serving JSON data utilizing RESTful architecture. But I want my own client apps only that can request from my web services. Basically, my web services contain sensitive data that is not for public consumption, but I wanted to build it that way so I can build many different client apps that connects to my...

RESTful-Authentication or Authlogic?

I'm having trouble deciding between the two. They both seem like great plugins but I'd like to know which is easier to control. What are your guy's experiences with these plugins? Which would you recommend? ...

Where does Rails use REXML lib and how to require that part?

I have a gem that uses some of the Rails libs, including action_view and active_controller. Though I require those libs, all tests fail when trying to call some has_text? method, which (as I found out) is part of'rexml/element' lib. Here's what I get: undefined method `has_text?' for "<b>Hello,<i>world</b></i>":String Requiring 'rexml...