ruby-on-rails

rails csrf token lifetime

hi, I use Rails request_forgery_protection mechanism to protect my POST actions from CSRF attacks and captcha to protect the GET actions. This way if someone stages a two-phase attack within one session, GET-ting the form with the current token and then POST-ing a forged request with that token, he will eventually be faced with a captch...

Sendinx faxes via Aterisk/Adhearsion/etc

Are there any HOWTO's? I want to send and recieve faxes in my rails app. So I'm looking for books/articles/libraries to read ...

Using HTML in Rails flash messages

I use flash[:error] to display a simple message to users that they cannot do a delete operation under certain conditions. I also have a link that will help them to get information about the entity that they wanted to delete and why they cannot do so. Is it advisable to include this hyperlink in the flash message? Which would mean that ...

Can I consume a SOAP web service using httparty or weary?

I am currently working on a ROR project that needs to consume some SOAP based web services. What I know about consuming web services borders on the 'dangerous'. The example that the site provides is using asp with XMLHTTP to send what appears to be some XML wrapped in a SOAP envelope. Included in the XML is the authentication informat...

Rails: remove port from _url helper

Hi, When calling the _url helper in rails it will return host+port+path so for example photo_url will return http://localhost:3000/photo In my production environment I have thin serving the rails application on a given port and apache serving static content on another port. When the site is accesed without any port each server kno...

OpenID for rails app behind Apache

Hi, I'm trying to integrate simple OpenID authentication through Google accounts. I'm using omniauth gem and on my local development system (Win7, ruby 1.8.7-p302, rails 2.3.8, omniauth 0.1.5) everything works nice. The problem shows it's face when I deploy it to my hosting (HostGator). The app (mongrel) starts at port 12002 and through...

Profile a delayed_job task in a Ruby on Rails app/Memory leak

Hi, One of my delayed_job tasks has a serious memory leak and I'm having a hard time solving it. Can anyone recommend a good tool for profile a delayed_job task in order to solve this memory leak? Regards, Rubem ...

Testing file uploads in Rails: can't convert ActionController::TestUploadedFile into String

Hello, Having problems testing a (working) upload in my Rails app (using 2.3.8): class ProfilesControllerTest < ActionController::TestCase test "creates a new profile" do fixture_image = fixture_file_upload("#{RAILS_ROOT}/test/fixtures/files/avatar.jpg", 'image/jpeg') post :create, :profile=>{:username=>'johndoe', ...

get validations from model

How cat I get list of validations defined in model Example: class ModelName validates_presence_of :field_name validates_inclusion_of :sex, :in => %w(M F) end I need Hash like: {:field_name => 'required', :sex => 'Must be in: M, F'} ...

Rails nested resources: Input vs. output format inconsistency

Given the following two models: class Company < ActiveRecord::Base has_many :departments accepts_nested_attributes_for :departments end class Department < ActiveRecord::Base belongs_to :company end I can now create a company and its departments in one go: @company = Company.create! params[:company] In this example params[:co...

Ruby is 1.8.7 but still get the unsupported version error when updating rails in Leopard

Espresso:Preferences PowerBook$ ruby -v ruby 1.8.7 (2010-08-16 patchlevel 302) [powerpc-darwin9] Espresso:Preferences PowerBook$ rails -v Rails 1.2.6 Espresso:Preferences PowerBook$ gem -v 1.3.7 but when updating rails, It still get the error Espresso:~ PowerBook$ gem update rails Updating installed gems Updating rails ERROR: Error i...

How to loop through ActiveRecord values in Rails?

I have the following columns in my table: value1 value2 value3 value4 value5 I want to be able to loop through them like this: <% for i in 1..5 %> <div><%= user."value#{i}"</div> <% end %> Of course this code doesn't work, so how can I get the value from an ActiveRecord object with a string? ...

how to display content with raw html

Hi, @post.body has following content (which is converted from Markdown by using RDiscount).How should I render it to the user in what it means? i.e I want to render it as strong text emphasized text... <p><strong>strong text</strong> </p> <p><em>emphasized text</em> </p> <blockquote> <p>this is a quote</p> </blockquote><p><img src="ht...

Certificate errors when using Devise with Facebook Oauth

Hi all- I'm using devise with oauth and Rails 3 (ruby 1.9.2) to log user's into my site. I followed this excellent blog post. That being said, I am getting a weird OpenSSL error, that seems to be due to some kind of certificate verification error. Heres what it looks like: OpenSSL::SSL::SSLError in Devise/oauth callbacksController#f...

Should I make a different join table for the same type of relationship?

I have posts that can be voted on by a polymorphic association. Now I am making comments votable as well. Can I share the same models and logic for this for my comments? Or do I have to make a new model relationship ? #post.rb has_many :votes, :as => :votable has_many :...

Fragment caching with Touch

Hi, Currently I am using fragment caching with an object key. And I expire the cache using Touch with updates the updated_at column and then the current cache become obsolete. And a new cache is generated the next time. <% cache do product %> The cache key for an object looks like this table_name/ID-updated_at Now I want to cache m...

fields_for doesnt working when form_for use symbol

i have a form_for code <%form_for :a,:url=>{:controller=>"biz/a",:action=>"save"},:html =>{:multipart => true} do |f| %> ..... <%f.fields_for :b do |b|%> ..... <%b.fields_for :apples do |apple|%> ... <%end%> .... <%end%> it outputs the html code without fields_for function <textarea cols="40" id="a_b_apples_content" name="a[b][appl...

Rails - Join each

Sorry, I don't really know how to title this question. Here's my code in view: <% country.cities.each_with_index do |city, i| %> <% city.shops.each do |shop| %> <%=h shop.name.join(", ") %> <% end %> <% end %> So in this city, let's say there are three shops: Walmart, Ace Hardware, Harman Kardon. The result of the above code...

getting ActiveRecord::RecordNotSaved error while saving.

While creating a new object i am getting ActiveRecord::RecordNotSaved error on before_save. But i want to fetch the proper message other than ActiveRecord::RecordNotSaved error message. How may i fetch the proper error message and pass it to the rescue? begin #some logic raise unless object.save! rescue ActiveRecord::RecordNotSa...

Uploading to S3 on Heroku with Paperclip (delayed_job question)

I'm trying to upload to a portfolio app I've built, specifically trying to find where to hook delayed_job into the process. It all works otherwise. Right now it returns undefined method 'call' for #<Class:0xae68750> on app/controllers/portfolio_items_controller.rb:18:in 'create' so here's my model and that portion of the controller... an...