ruby-on-rails

Route to nested model/form for unsaved parent

I have a complex form for a model Schedule that belongs to a parent Listing model: class Listing < ActiveRecord::Base has_many :schedules, :dependent => :destroy accepts_nested_attributes_for :schedules, :allow_destroy => true, :reject_if => :all_blank ... end class Schedule < ActiveRecord::Base belongs_to :listing ... end ...

textarea character count in Rails

Hello, I want to use observe_field to give me the character count of the textarea, updated as you type. What am I doing wrong here? <div class="field"> <%= observe_field :micropost_content, :function => "$('micropost_content').value.length" %> <%= f.text_area :content %> </div> ...

jquery-in-place-editor pre post hooks?

I'm using jquery edit in place lib and I'm having a problem when trying to use a class selector to select multiple editable items. I'm calling editInPlace on an array of elements so I don't have to repeat that call for each editable item. What I can't figure out is how to append the item id to the url. I'm using rails so I need a url ...

Opposite of rails initializers (2.xx)?

I run several daemons in config/initializers/ when I start my rails app, but I need a way to detect when the app is shutting down, and stop the daemons. Are there any hooks / places where I can do this? ...

Authlogic and OpenID registration and login in one action

I was playing with Rayan Bates http://railscasts.com/episodes/170-openid-with-authlogic sources as the basis. So I created few icons for OpenID providers, like Google, Yandex, OpenID, and user have to choose which one to use (similar like here on stackoverflow). So everything is fine. Now I decide to make only one click for login or reg...

how to request a page in xml in ruby-on-rails?

here is my code in a controller respond_to do |format| format.html format.xml { render :xml => @menus } end when i type "http://192.168.210.136:3000" then it renders the html version. but how do i request the xml version? i tried http://192.168.210.136:3000.xml and http://192.168.210.136:3000/index.xml with no luck. thanks! ...

Easily create a Ruby on Rails partial from an existing block of markup using vim

Is there currently a plugin that you ruby on rails developers that are also using macvim/gvim/vim that allows you to take a quick block of code and create a partial from it? I know that TextMate does this, figured someone has ported it by now to vim also. ...

ActionMailer Doubt in Rails

My Application has a lot of modules like profiles, places, comments etc. So Inorder to send a mail when something interesting happens like a new comment, a new place, do I need to create many mailer classes(ProfileMailer, PlaceMailer, CommentMailer) and also corresponding observer classes to implement mail? ...

Rails - Using Autocomplete with the Scoped_search gem?

I'm using the scoped_search gem for basic search functionality on my site. Scoped search: http://github.com/wvanbergen/scoped_search I'm using the most basic possible implementation of this gem. I'm searching on the name attribute in a user model only. On the frontend, in users/index, the search input is a text_field_tag. <% form_t...

How to count the number of occurences of urls and hyperlinks in a Ruby string?

Say a user submits this comment on a blog: @SO - Great community, but we've also seen some great communities at Stack Overflow. At the same time Google's Gmail (http://gmail.com) is a great example of a community with endless bounds. I'm just wondering if anyone will really go toe-to-toe with something like http://www.t...

Capistrano deployment changing directory for migrations

I have a rails app that is not in the root directory of the repository. When it is deployed, some other static files are deployed with it in a parent directory. The structure is something like this: root -- otherstuff -- railsapp When I do a deployment with cap deploy:migrations, the Capistrano command that gets executed looks like th...

Determine if path exists as route in Rails controller

I want to know if an arbitrary path can be mapped to a route recognized_request_for accomplishes what I want, but I can't get it to work in my controller. Specifically, how can I execute recognized_request_for or something that accomplishes the same task from my controller? ...

Rails Join Table without Model

Is it possible to create a join table without a model. I have a model called User and Pet. I want user to have only one pet and pet to only have one owner. Very simple. However, I am trying to figure out how to create a join table pets_users that has both users.id and pets.id in it without having to create the actual model. Is this poss...

Ruby on Rails Server hangs/lags randomly for long periods

I have a program that makes a simple Ruby on Rails server go live. The server is used to communicate and collate data between computers on the same network. I have not done anything fancy to the Ruby stuff. I have simply used scaffold to generate 3 models and that is it. The problem is that after a while (many HTTP requests between the c...

Rails not picking up model attribute despite column EXISTING in table

== AddIpToTutorials: migrating =============================================== -- add_column(:tutorials, :ip_address, :string) -> 0.0022s == AddIpToTutorials: migrated (0.0022s) ====================================== >> t = Tutorial.new .. >> t.ip_address NoMethodError: undefined method `ip_address' for #<Tutorial:0x2b3b35f5a690> ...

Help clarify my thinking for rails associations

I'm building a rails app that allows athletes to create and manage timesheets for the sport of skeleton. I can't seem to wrap my brain around the correct associations between my models. Here's what I have so far. Athletes have Runs, which are composed of several Splits. Each individual split should be associated with a particular timing ...

Factor out application_helper

On my latest Rails application I've decided to only render partials from helper methods. For example, in application_helper.rb: def render_header render :partial => "partials/header" end I'm doing this to make my code a little more dry in case I rename a partial or need to add in additional logic for controlling which partial is...

Parsing problem with hpricot

I have an XML that looks like this: <data> <image src="http://www.someweb.com/something.png"/&gt; </data> What is the correct way to use hpricot to extact just 'http://www.someweb.com/something.png'? The closest I can get is this... >>(doc/"image").first => {emptyelem <image src="http://www.someweb.com/something.png"&gt;} I've re...

Strange routing in rails render partials

I'm new to rails and thought I had finally figured out some of this routing stuff, but have been going in circles with this bit all day. I was following a tutorial about building a twitter like service, and I've got the basics working from the tutorial, but with Mongo instead of mySql. I've got 3 types of pages. The home page which i...

RoR noob: How do I access a counter inside an iteration?

My google skills are failing me big time. If I have a standary RoR loop like this: <% @notes.each do |q| %> <% end> How do I access a loop counter from inside the loop? Thanks for reading. ...