ruby-on-rails

Ruby On Rails Web Application Development From Scratch?!

Background I am interested in getting to grips with some Ruby On Rails. I've got 4 years experience programming in C#, ASP.Net, ASP.Net MVC, SQL Server and more recently Silverlight etc. Obviously I've got a pretty good understanding about the various implementation routes that you can go down when writing web applications using C#, the...

IronRuby On Rails VS. Ruby On Rails (Getting Started)

The Scenario I am a C#/ASP.NET/MVC/Silverlight developer with a few years experience. I'm trying to kickstart my Ruby On Rails learning. I'm currently trying to get a real feel for ROR. I Want To Know Standards As a .Net developer, you tend to use a standard IDE (Visual Studio), a few standard databases (SQL Server, Oracle etc.), and ...

STI and has_many association with "type" column as Key.

I am using Single Table Inheritance for managing different types of projects. I decided to store some information associated with each project type. So i created new table "project_types" with "model_type" field as primary key. Primary key values are values of "type" field of "projects" table. Problem: When i trying to get associated wit...

form_for using :symbol not working, error [Only get, put, and delete requests are allowed]

When submitting a form to create a new object i get an error message when submitting the form. When i use the same form but then with an instance variable everything seems to go fine, any clue why the submit with the :symbol fails? The error message says: Only get, put, and delete requests are allowed. The code for the new form with :s...

Creating Single Table Inheritance Records in Rails

I'm using single table inheritance for my application. My polymorphic type is Maintenance with only one subtype, right now, named OilChange. I'm running into problems creating my records in my create method in the controller. Here's the code. @log = Log.new(params[:log]) @log.maintenance = Maintenance.new(params[:maintenance]) The ...

Tracing SQL queries created by Ruby-on-Rails

Hi, In the web application I am currently developing, I have quite a few database queries being performed. I would like to know what parts of the code are producing these queries so that I can perhaps refactor the code to reduce them. Is there an easy way to do this? Typically, the database queries are like: SELECT count(*) AS count_a...

Rails Test & Mocha: How to stub specific model - conditional any_instance ?

I want to stub just a specific model, but not only a specific object and not every instance E.g. Given class 'Person' with attributes 'name' (string) and 'cool' (boolean). We have two models: person_bill: name: bill cool: false person_steve: name: steve cool: false Now I want to stub just steve, which works alright: p1...

Rails attr_accessible does not work for :type?

Im trying set the single table inheritance model type in a form. So i have a select menu for attribute :type and the values are the names of the STI subclasses. The problem is the error log keeps printing: WARNING: Can't mass-assign these protected attributes: type So i added "attr_accessible :type" to the model: class ContentItem...

rails - apply complex visibility settings to thinking sphinx results

in the product i'm developing, i have a Message model. Message can be restricted to groups, or not restricted (available to everyone). If user belongs to one of Message's groups OR message is not restricted, user can see the message. here is the query selecting visible messages (in hope that it can clarify what i mean) (2,3,4,5,6,1) ...

Rails environment specific validation

I'm using this plugin called validates-existence-of-uri in my model as follows: class Project < ActiveRecord::Base validates_uri_existence_of :link, :allow_redirect => false end Its working and fine. And I've a seeds.rb file which seed the data using Faker to generate urls So, while seeding the data, the above validation tries to ch...

Exception with javascript_include_tag with Phusion Passenger in Rails

Hi, In my Rails app. the javascript_include_tag seems to work fine in my localhost (mogrel) but I move to production(Phusion Passenger) it seems to behave differently and I get the following exception: (not sure what it's asking for all.js!!) A ActionView::TemplateError occurred in posts#show: Permission denied - /var/www/war/releas...

Formtastic and Formtaghelper

I'd like to create a user registration form where the user ticks some boxes that do not connect to the model. For example, there might be a 'terms & conditions' box that I don't want to have a boolean field in the User model saying 'ticked Terms & Conditions'. Instead I want to create a record somewhere else (like a transaction) that re...

find all children of an object tagged with acts_as_taggable_on

I have a rails site with two models: events and dates events has many dates events are tagged using acts_as_taggable_on I'm trying to find all dates (chronological order) for events tagged with a specific tag. I can figure out how to get all the tagged events, but I can't figure out how to get all of the dates. The end result I'm ...

How to DRY this snippet of Ruby code?

This is bothering me. It doesn't look too DRY. What would be a better implementation? As an aside, how come this ActiveRecord finder doesn't throw an exception when record is not found, but .find does? def current_account return @account if @account unless current_subdomain.blank? @account = Account.find_by_host(current...

Rails with in memory database

Can I set rails to use mysql with MEMORY as the DB engine? I never restart mysql, and rebuild the db so often I'd rather have it be fast. Having the memory db for running tests would be nice too. EDIT: I should have specified this is for dev/testing only, not production. ...

Which modern web frameworks are popular in a corporate setting?

My company is looking to move their software to an open source framework. Their first thought was J2EE. I know that Django and Rails are popular for recreational development, but not sure about them in a corporate setting. I was looking to compile a list of possible web frameworks to consider. Unfortunately I am not able to release ou...

YAML Encoding of Malformed String, Model Serialization Issues

I've isolated a problem with Ruby on Rails where a model with a serialized column is not properly loading data that has been saved to it. What goes in is a Hash, and what comes out is a YAML string that can't be parsed due to formatting issues. I'd expect that a serializer can properly store and retrieve anything you give it, so somethi...

Rails Lameness Filter?

I've done some searching, and I haven't been able to find any kind of open-source lameness filter for rails. Does anything like that exist? I'm trying to curtail lame user generated content, in particular, all caps, improper capitalization, excessive exclamation marks, and excessive bold or italics. ...

Rails - Separate Database per Subdomain

Hello all, I am about to begin writing a Rails application that will allow clients to have a separate subdomain for their access to our application. Thinking from a data security standpoint, it would be nice if each client's access was truly limited to their database, that way, if there is a bug in production code, they would only be ab...

Creating a generic HTML header with blocks in Rails

What I want is to do something like this in my views: <% page_header "Your Posts" do %> <div class="add"> <%= link_to 'Add a new post', new_posts_path %> </div> <% end %> And have the HTML render something like this: <div class="page_header"> <h2>Your Posts</h2> <div class="add"> <a href="/posts/new">Add a new p...