ruby-on-rails

Parsing in Ruby (on Rails)

I want to write a Rails app to assist me with my online Poker. I play on PokerStars, and there is text data available for each hand that is played. The format it comes in is this: PokerStars Game #27457662450: Tournament #157033867, Freeroll Hold'em No Limit - Level IV (50/100) - 2009/04/24 20:39:44 ET Table '157033867 830' 9-max Seat ...

Rails has_and_belongs_to_many join across 3 tables

I have a three models: listing, category, and site. There is a many to many relationship between listing and site and there is a many to many relationship between listing and category. A listing thus belongs to one or more sites and one or more categories (a listing can appear on multiple sites and multiple categories). Given a site i...

Find all objects with no associated has_many objects

In my online store, an order is ready to ship if it in the "authorized" state and doesn't already have any associated shipments. Right now I'm doing this: class Order < ActiveRecord::Base has_many :shipments, :dependent => :destroy def self.ready_to_ship unshipped_orders = Array.new Order.all(:conditions => 'state = "...

Inserting > at the start of each line in reply e-mails

In my Rails app I have a mail section in which I want to append a > character at the start of each line when replying to a message. The challenge is, how do I know when to insert a > character given the block of text doesn't contain carriage returns according to the width of the textbox. ...

One-Click install for Ruby/Rails/SQLite?

I'm really excited to start programming in Ruby with the Rails framework; I've read great things about Ruby on Rails! I've gotten myself a couple of books, thumbed through a few tutorials, read some forum threads, but I'm already stuck on Step One: Installation. I guess I'm more used to the One-Click install local environments of MAMP. ...

How can I send date object from Adobe Flex to RESTful rails?

Hello, I'm working on an Adobe AIR project that use the Ruby on Rails as RESTful web service as the back end. I have found a lot of examples that show how can I send the data to operated by Rails. but I stuck at date object, which will be very useful if I can send Actionscript's date object to Rails via XML or whatever and Rails can und...

How do I do an OR SQL search with Ruby on Rails?

Hi There, I am just beginning to learn Ruby on Rails, and I haven't been able to find the answer to this question. I have the following code: @products = Product.find(:all, :conditions => ["productsubtype_id = ?", @productsubtypes], :order => "name") @productsubtypes is an array (currently containing two objects from another SQL...

Faster/bulk activerecord creation

My application is storing location data from GPS inputs. When importing a GPX file, a user can have from 500 - 10,000 GPS datapoints. Right now, I have a model for each trackpoint. It's working great, but on insert it is SLOW. 30+ seconds for the 10,000 datapoints. Is there any better way of bulk inserting? All the time is spent ...

I don't want to learn PHP. Should I avoid learning it?

I've been programming in Ruby on Rails for a year now. I looked at some of the PHP code of WordPress and its e-Commerce plugin. This is not going to sound professional, but it looked disgusting. Having only done development in an MVC framework, I can't imagine how is it possible to work without those patterns. There also seems to be no a...

RoR: how do I create a "valid signup code" lookup?

Hi, I want to be able to give codes to potential users in the form of email links (e.g. mysite.com/signup?beta=rapunzel) When someone clicks on the link, it populates a hidden_field with the value (will just using :params[:beta] work?) Then before it creates the user it validates by checking against another table where I have differen...

Facebooker: Redirect after fb_user_action

I'm trying to user Facebooker to publish stories to Facebook. When a user submits a form on my site, I'm using fb_user_action to show the dialog asking if a story can be published. When that is dismissed, I want to redirect to a different page. Facebook's documentation for showFeedDialog talks about the continuation parameter. It takes ...

conditional view/layout

Say there is a product controller which you want to have an index (list products) action. Easy. Now say you have an admin and store parts in your project. Both need to list products, but in a slightly different manner (store's one shouldn't have this edit product link for instance). They also use different layouts. So far my idea is to ...

How do I write a Rails chatroom?

I need to make a chatroom for my Rails app. Are there any good tutorials for writing one? Will it be a non-Rails technology that I simply plug in or are there some Rails libraries that are meant for it? I want to save each message to my PostgresQL database, and I want all previous messages to be visible - a perpetual chatroom. ...

How to write a link to a public file

In my Rails app, I have some files in the /public directory which I want to write hyperlinks to in the views. How do I do this other than writing old HTML like <a href... Is there a neat link_to way? ...

Best hosting for student's practice and pet projects? Should support rails

Hi I'm looking for the cheapest hosting that would allow me to deploy a number of rails and non-rails apps along with maybe a blog and other goodies. Traffic is likely to be rather low, but still important. Like a portfolio site. What are good hosting providers for that? ...

Issues concatenating to an array constant for options_for_select

Hello, I have the following code: <%= select_tag :role, options_for_select(Project::COMPANY_ROLES.concat(['Other...']), @relationship.role) %> For some reason it concatenates "Other..." to COMPANY_ROLES but saves this past the view that was loaded. 1st Run = 1 option of "Other..." 2nd Run = 2 options of "Other..." 3rd Run = 3...

Viewing a Ruby on Rails script in my native browser

I'm new to developing in Ruby and have mostly been using irb to experiment with code. For longer scripts, it would be helpful to be able to run them in my native browser (similar to how I run php scripts through MAMP). I believe there is a way to do this using localhost:3000 but I have not been able to get it to work. So my question i...

How to prevent backgroundrb from starting multiple copies of the same task?

Say, I have a worker that's set up to run every 15 minutes using the cron scheduling feature of backgroundrb. Then, say, if a single instance of the worker takes longer than 15 minutes to run, I don't want a second worker to be started in paraller by backgroundrb. How do I achieve that? ...

Using :attr_accessible with role-based authorization

In my online store, users are allowed to change certain properties of their orders (e.g., their billing address), but not others (e.g., the origination ip address). Administrators, on the other hand, are allowed to modify all order properties. Given, this, how can I use :attr_accessible to properly secure my Order model? Or will I have ...

Evaluating :dependent => :destroy

In Rails 2.2.2 (ruby 1.8.7-p72), I'd like to evaluate the impact of destroying an object before actually doing it. I.e. I would like to be able to generate a list of all objects that will be affected by :dependent => :destroy (via an object's associations). The real problem I'm trying to solve is to give a user a list of everything tha...