ruby-on-rails

making a pretty url via ruby

Ok so i want the title of an event to be in the url like /events/party-at-mikes so here is how i am doing it Event.find_by_title(params[:title]) my link <%= link_to('<span>EVENTS</span>', course_event_path(obj.golf_course.city.permalink, obj.golf_course.permalink, obj.title), :class => 'right eve_bnt') %> the obj.title is the ...

Rails background/async task requirement

We have a rails v2.3.8/apache/passenger application & have async requirements for some long running tasks. So I have been evaluating some solutions around rails/ruby, wanted to get feed back on some of the solutions. Also I had one question - on how do the background tasks/workers get spawned. Given our rails app will run inside a apach...

Don't know how use 'serialize' method in rails

i have a model called user class User < ActiveRecord::Base serialize :friends end when running the console script and create a new object of User class user = User.new user.friends i found a 'NoMethodError' should i write the serialize calling in another file? OR what should i do to make the friends array an attribute for the ...

Why did Rails ignore my user_id field?

I tried creating a DB migration in Rails that looked something like this: ruby script/generate scaffold post user_id:int title:string content:text Looking at the resulting .rb file, sure enough, I saw everything I'd entered: class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.int :user_id...

Adding variables from object passed from model to controller

I have a Person model. When a new Person is created, I want to set a random_variable in the controller and pass it as part of the @person object. I have tried Model attr_accessor :random_variable Controller: def create @person = Person.new(params[:person]) @person.random_variable = 'A Random string' @person.save ...

Login using Rails Devise and Adobe AMF3

I am trying to login in to my Rails app through an adobe flex application that uses Devise but cannot figure out how to map the AMF request to Devise::SessionsController#New. I tried the following <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="librar...

How to arbitrarily separate navigation items using simple-navigation?

I can't figure out how to configure my navigation so that I can call out different parts in different places in my layout, other than to use the 'level' system provided. Really my navigation isn't two 'levels' - I just want some of it rendered in one div and some rendered in another. I could hack my application's navigation such that o...

how to measure page request time in milliseconds in a rails project?

New to rails, want to test the time it takes for a given page to render in milliseconds. Where in the request pipeline do I do this? (start and stop the time, and output to the page) ...

If I change the database in a live Ruby on Rails app, how do I update the data?

So I'm finally ready to allow some friends to use my Ruby on Rails app, which I'm hosting on Heroku. I want to start getting some feedback as I'm still developing. What happens if I need alter to the database in some way? There will be data in the database, so I will have to change the data to reflect the updates in the database, but I'...

user.find(1) results in an exception, is my system ok or my setup is messed up?

My database is empty, and I understand that I should get an exception. Just want to make sure that my macbookpro is setup with rails properly. typing: user.find(1) in console I get: >> user.find(1) NoMethodError: undefined method `find' for #<User:0x1016403a0> from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.0/lib/active_model/a...

What is the simplest way to create a very simple widget that can be used on remote sites?

For example, I have a super simple widget that I want to allow my users to use across sites: <h1>Headline</h1> #mingyeow is the name of the user <% render "/questions/mingyeow" %> What would be the easiest way to do? exact method to allow this javascript vs iframe cross site security concerns ...

Remove String from View as save as Cookie

I have a database table with records and I show them on a view page, as below. my question is: If I click "Destroy" Button the corresponding "quote" should not be deleted from Database but it should be removed from view page for my browser only (using cookies?) (not affected for other computers). How can I implement this ? Thank you....

Static Nested Elements in Rails

I have a list of 'Interests' that each user in my system has the ability to rate. An admin can add/remove Interests at any time. When the user goes to edit their account, I want to show a list of all the Interests in the system, and a drop down with a 1..5 value. I am wondering how I set this up.. Using accepts_nested_attributes for doe...

Executing Rails virtual attribute setters in order

I have an ActiveRecord model with several virtual attribute setters. I want to build an object but not save it to the database. One setter must execute before the others. How to do? As a workaround, I build the object in two steps @other_model = @some_model.build_other_model @other_model.setup(params[:other_model) Where setup is: cl...

Creating forms for polymorphic associations in Rails

I have a couple classes that can each have comments: class Movie < ActiveRecord::Base has_many :comments, :as => :commentable end class Actor < ActiveRecord::Base has_many :comments, :as => :commentable end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end How do I create a form for a n...

How can I authenticate my POST request via OpenId on the commandline

I want to add entries to my RESTful Rails blog using HTTP POST requests. I have a script that does this easily enough, but it only works for my development app because I don't require it to authenticate. Now that I'm publishing my site, I obviously need to authenticate my uploads before posting them. The rest of the admin stuff is behin...

RoR call thickbox from rjs

hi, on clicking link, the action will be called, with in the action i am using code below.. page.replace_html('replace', :partial=>"my_things") here, i want to see this replacement in side thickbox.. please guide me with the code to,call thickbox inside or from rjs.. thanks ...

Different tags in ERB

I'm just getting started with Ruby and Ruby on Rails, so excuse me if this is a simple question. I've noticed that in some ERB files, there is a difference to using <%= %> and <% %>, but what is the difference? Thanks! ...

How to prevent pipe character from causing a Bad URI Error in Rails 3/Ruby 1.9.2?

In implementing OAuth2 in my app, I need to handle URIs like: http://localhost:3000/sessions/create/?code=lorem|ipsum Not sure if it's a Rails 3 or Ruby 1.9.2 problem (maybe URI.parse), but in any event, WEBrick kicks Error bad URI. Anyone know of a workaround? Thanks. ...

activerecord nested conditions

this is a follow up to a previous question i asked. i am having trouble getting a query to work that has a variety of conditions for nested models. user has_one avatar user has_one profile avatar belongs_to user profile belongs_to user and i am actually able to get this to work... Avatar.find(:all, :include => {:user => :profile}, :...