ruby-on-rails

Ruby on Rails, AJAX examles

Hi, I'd like to know what people think what websites are good examples of AJAX with Ruby on Rails at the moment. I'm learning both and would like to see some good interesting examples of what can be done. THanks, Joe ...

How to use a Rails environment variable in Capistrano deploy script?

If I have a constant in my Rails environment.rb, for example... SOME_CONSTANT = 3 Is it possible to access this in my capistrano deploy.rb somehow? It seems simple but I can't figure out how. ...

Rails routes - index page for subdomain and standard url

Hi, I am using the account_location plugin in my rails app and have the following route map.root :controller => "dashboard", :action => 'index' This route match's on both subdomain.domain.com and www.domain.com How can I set it up so these two domains match different routes? Thanks, Andy ...

Insert javascript call inside <body onLoad=function()> in RAILS

Hi, I am n00b at rails. The question is very simple, i want to know how can i make a javascript function call inside body tag on the onLoad event. I'm asking this because in the views i can't find any body or head tag (It's like they are generated elsewhere). Thanks ...

routing issue, rails generates wrong url.

First of all, Happy Thanksgiving. So my issue is with my routes, I'm not clear on why id param actually contains the entire object. Rails gives me this error: user_url failed to generate from {:action=>"show", :controller=>"users", :id=>#<User id: 19, username: "Dr. Dorothy Buckridge", email: "[email protected]", crypted_password: ni...

more methods for before_validation

Is possible set 2 methods on before_validation in a model? before_validation :elaborate before_validation :download_remote_data, :if => :data_url_provided? Thanks ...

Errors while testing a Rails application

Hello. I'm new to RoR and I'm trying to test my app. In my sample app, I have in user_test.rb: require 'test_helper' class UserTest < ActiveSupport::TestCase def test_truth assert true end end The error I'm getting is: Z:\web\rails\pbbg\test>ruby unit/user_test.rb c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.3/l...

How do I use cookies to store complex information and subsequently dynamically trigger an action based on the data?

Hi All, I have a simple (yet somehow convoluted) issue. Basically I'm adding items to make my web app more "desktop-like". For instance, right now I'm trying to get a page to dynamically load info into a DIV based on previously selected items. I'm currently using a cookie to handle saving the data, but I can't for the life of me get ...

one-many-many assoc find conditions

Hello all! I've got the following models: project.rb has_many :tasks task.rb belongs_to :project has_many :assignments has_many :users, :through => :assignments user.rb has_many :assignments has_many :tasks, :through => :assignments assignment.rb belongs_to :task belongs_to :user So for example: Project.first.title #=> "Manh...

Rails storing host password for FTP model

I'm building a rails app that communicates with other servers via ftp. The user needs to input their host, username and password for their particular ftp server. I wouldn't want to store their password as cleartext, but I need the actual password to connect to the server when it comes time. Would it make sense to use a two-way hash? ...

Ruby/Rails: converting a Date to a UNIX timestamp

How would I get a UNIX timestamp (number of seconds since 1970 GMT) from a Date object in a Rails app? I know Time#to_i returns a timestamp, but doing Date#to_time and then getting the timestamp results in something that's off by about a month (not sure why...). Any help is appreciated, thanks! Edit: OK, I think I figured it out- I w...

Sending registration verification e-mails using Authlogic?

Is there any way I can get authlogic to send email to my subscribers after they have registered so that they can confirm their account? ...

Populate form fields using a dropdown and AJAX with Rails

I have a form field where a user enters contact information, including name, email, etc. If they already have contacts saved I want to have a dropdown with their saved contacts. When a contact from the dropdown is selected, the contact fields should be populated with that data to allow for easy editing. For some reason this approach isn...

How to truncate text until "more" link is clicked?

I have a long series of paragraphs and I'd like to trim each down to 2 lines (50 characters) and when you click a link "more" it will show the full paragraph. I am using the prototype library and rails. I'd ideally like to do this with out breaking the paragraph into 2 divs and showing the other when you click on more. Or is that the o...

(ruby) ruby sockets: how to create a POST request?

How does one create a POST request using TCPSocket in Ruby? Is there a special format to making a post? I have the following but I get a parse error (it's for a rails server): require 'socket' s = TCPSocket.open("localhost", 3000) s.puts("POST /<controller>/<action> HTTP/1.1") s.puts("Host: localhost:3000") s.puts("Content-Type: applic...

RoR plugin/gem for html validtion

I am wondering if there is such a plugin or gem for Ruby on Rails that includes HTML validation (SGML or Tidy) in a testing cycle. I am aware only about this plugin. Looking for alternatives... ...

Testing rails routes: can't find ActionController::Assertions::RoutingAssertions methods

I'm trying to test the routes on my rails 2.3.4 application. There are several sites that explain how to test routes, including the rails docs, but I'm getting errors following the instructions. First, I'm assuming that these tests can be done in related unit test files. There seems to be no more obvious place, and none of the docs spec...

Rails virtual attribute search or sql combined column search

Hello All! I have a user model with attributes 'first' and 'last' So for example User.first.first #=> "Charlie" User.first.last #=> "Brown" This User model also has a virtual attribute 'full_name' #user.rb def full_name [first,last].join(' ') end def full_name=(name) #don't know what to do with people w/ middle names split = name...

How to handle HTTPStatus Response 201 with AS3 / Flash / SWFUpload

Hey all. I'm using SWFUpload on a Rails site to allow for MP3 Uploads direct to Sound Cloud. To avoid having to first upload a large file to my server and push to Sound Cloud, I'm hitting their API directly via SWFUpload, passing necessary OAuth token data. Everything works - EXCEPT - Flash can't handle the HTTP response code that Sou...

Help solving a routing error in Rails

I have a controller called form_questions_answers with a method in it called modify_rule but when I perform a post to /form_questions_answers/modify_rule/60 Rails tells me: Routing Error No route matches "/form_questions_answers/modify_rule/60" with {:method=>:post} Why is this happening, I have map.resources :form_question_answers in...