ruby-on-rails

Deleting Records with Ajax in Rails

I have a user page where the user can type and submit posts. I'm using Ajax to allow the user to do this from the user/show page. The problem that I'm having occurs when I try to let the user delete posts. When the user clicks the "remove" link, the post is removed from the page. However, when I reload the page, the post is back. It's...

Ruby on Rails question - how can I measure response time from when request first hits app?? (e.g. using 'benchmark')

Hi, Background - I'm serving files (text, images) to a browser via my Rails application as the user needs to be authenticated too. The files are on file system, however references are in the database, as I'm using PAPERCLIP. Using AUTHLOGIC for authentication. I'm finding the response times are quite bad, as each request for HTML/ima...

Rails / Snow Leopard Mysql 64-bit question

Hey all, I'm trying to install 64-bit MySQL on Snow Leopard for a rails app. I've installed it from the dmg and I can get to mysql fine from the command line. Based on various blog posts as well as the other topics here on Stack, I shut down mysql, uninstall the mysql gem, and then try to update the gem with the following: sudo env ARC...

Rack Bug Installation issue. Server does not start

I just installed the Rack-Bug and created the middleware file that it needs in the config folder. But I am unable to start my server. Im using Rails 2.3.4 with Ruby 1.8.7. /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant IPAddr (NameError) fro...

Rails html encoding

I am using h helper method in Rails to encode/escape a string that has an apostrophe (') In my view I am using it like this <%=h "Mike's computer" %> My understanding is that the html when viewing the source should be Mike%27s computer but the html produced has an apostrophe in it, Mike's computer Am I missing something obvious? Ho...

How to create an instance of an uploaded file programmatically in rails

I want to create an instance of "uploaded_file = ActionController::UploadedTempfile" from a File.new("path/to/file"), and then go on to do processing on "uploaded_file" like so: uploaded_file = ActionController::UploadedTempfile.new(File.new "path/to/file"). But for everything to work correctly, I need to set it so that uploaded_file...

Rails - Send emails through an exchange server

How does one use an exchange server to - Send an email from a rails application Authenticate credentials (user name / password) Thanks. ...

How to write rails Controller to simulate update twitter-API like ?

I want to write rails controller to allow user to update resource through json or xml like update status in twitter. I tried to create some dummy controller like def visit ... end and add route map.connect 'users/visit', :controller => 'users', :action => 'visit', :conditions => {:method => :post} but when I tired post some data...

Force www. in rails

Hey, I'm normally used to using .htaccess files to force a domain to use www. (i.e. http://www.example.com instead of http://example.com): #Options +Indexes RewriteEngine on RewriteBase / Redirect permanent "www.example.com" "http://www.example.com" Redirect permanent "example.com" "http://www.example.com" However this doesn't work ...

[Rails] reuse logic in views (javascript) and model

Hello, i have some logic to code in my model to calculate the number of business days between 2 dates input by the user. In my view i would like to display the same number of business days before the user submits the action... Is there a way to do this without duplicating code? I'd rather avoid an AJAX request (as it seems a bit overk...

rails3 generator loading

I am working on creating a rails3 generator that integrates with the existing model generator so that if I use --orm=data_mapper and have it generate a data mapper model instead of an activerecord model. This I have done successfully. I have created a generate that will generate the data mapper model. The problem comes when I try to p...

How do I make Ruby read .cer public ssl key?

Hey, I am working on a RoR website that requires an e-payment module. The e-payment implementation requires that the xml data is encoded using a public ssl key provided by them. What I tried to do in Ruby: public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file)) If I just try to open the file separately it works fine. But the...

Can I create an *un*named scope in Rails?

I know you can create named scopes in Rails, which allow you to specify conditions which can then be built on later: named_scope :active, :conditions => {:active => true} ... MyModel.active.find(...) This works by creating a proxy object which isn't evaluated until later on. What I want to know is if it's possible to create a dynami...

using paperclip with secure and non-secure files

First off, we have this namespaced/sti'd structure for our different types of 'Media' Media< Ar::Base Media::Local < Media Media::Local::Image < Media::Local Media::Local::Csv < Media::Local etc... etc.. This is excellent since a user can have many media, and how we display each piece of media is based on the class name and a co-resp...

How can I delete an entry from a HABTM join table in rails?

Through many iterations of testing, I just noticed that my join table that represents a HABTM relationship between two models isn't removing entries when instances of these models get deleted. Do I need to do something special when removing an instance of a model that has HABTM relationships? ...

ActiveResource client not behaving as expected

I have this code: require 'rubygems' require 'activeresource' ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/exercises.log") class Exercise < ActiveResource::Base self.site = "http://localhost" exercises = Exercise.find(:all) ex = Exercise.find(741) ex.name += "_TEST" ex.save end And the generated url...

Declarative_Authorization nested rules

My models are setup as Film :has_many :sections Section :belongs_to :film within my authorization_rules.rb I have role :author do has_permission_on :films, :to => [:edit. :update] do if_attribute :user => is {user} end end Which works fine when editing the film as their is a user_id field within film. Can I nest r...

nested iFrame facebook app with facebooker on IE

Hi all, I've tried to create simple facebook app with iFrame,, but I always get nested iFrame on every I click link on my application, I already tried a solution from site http://railsrant.com/2009/10/14/creating-a-facebook-iframe-app-using-ruby-on-rails-facebooker/ it's work on Firefox and Chrome, but doesn't work at IE Any idea or sug...

Stop images from caching in Rails and browser?

I have created a image crop facility that I can click on an image and crop it and it saves the new cropped image over the old one, then redirects back to the original page where the image was show. But it still shows the old image even after a redirect and doesn't display the new one till I refresh the page. I have tried just using an ...

When using ruby-on-rails how do you iterate over variables stored in the session?

I want to loop through all the variables stored in the session. I checked and it appears that sessions are stored as a hash: request.session.kind_of?(Hash) - returns true I wasn't sure why the following code didn't work: request.session.each {|key, value| puts keys + " --> " + value I am trying to output all session variables as part...