ruby-on-rails

Raisl 3 - howto ... Storing Unstructured Data in a database column field Data

Hello, I'd like to learn the smart way to store unstructured data in a DATA field so for example, if I have the Table AuditLog with the fields id | model_name | data And in Data I want to store various types of data which changes based on the model_name. I also want it in data so I can output these records w/o using JOINs for performan...

VPS Passenger-Apache Ruby on Rails. Rails does not route via hostname, only IP...

Hi, I have just setup apache and passenger on a new VPS. It is the first time i've deployed a rails app. I've got it all working, it's just that when i refer to one of the routes defined in routes.rb using "www.hostname.com.au/controller/action" it just boots me to the index page of my rails app. If i use "ip.ip.ip.ip/controller/acti...

Rails 3 - What's wrong with this CASE Statement?

<% @feed.each do |feed| %> <ul id="feed"> <%= case feed.action_type when "COMMENT" <%= render :partial => "feeds/storyitem" -%>, end %> </ul> <% end %> ...

undefined method 'password_confirmation' for User: Testing Authlogic with Cucumber and Factory Girl

My tests work fine when I'm testing them individually, rake cucumber FEATURE = 'path/to/feature' but when I try to run rake cucumber They fail with the following error undefined method `password_confirmation=' for #<User:0x1069545f0> (NoMethodError) This comes up when I try to create a user using Factory.build(:user). I have ...

How would I break up and extract an array from an array-of-hashes in Ruby on Rails?

for example: [ (id=>1, email=>'[email protected]', name=>'tim'), (id=>2, email=>'[email protected]', name=>'joe'), (id=>3, email=>'[email protected]', name=>'dan') ] How can I extract the email column and put it in its own array? ...

How do i download prawn pdf file while using form submit?

def index @forms = Form.all respond_to do |format| format.html end end def submit respond_to do |format| format.pdf {render } end end submit.pdf.prawn file pdf.text "successfully submitted" ...

Hacking ActiveRecord: add global named scope

I am trying to have a pack of very generic named scopes for ActiveRecord models like this one: module Scopes def self.included(base) base.class_eval do named_scope :not_older_than, lambda {|interval| {:conditions => ["#{table_name}.created_at >= ?", interval.ago] } end end end ActiveRecord::Base.send(:inc...

nil values magic

I have faced the plain simple situation, that i can't figure out. I have to deside, whether to show the "more" link, depending of the articles count The code is plain simple @no_more = offset + length >= Article.count @no_more variable equals to nil sometimes. I see in debugger, that offset=0, length=10 and Article.count=12 But the...

Problem with cyrillic characters in Ruby on Rails

Hi, In my rails app I work a lot with cyrillic characters. Thats no problem, I store them in the db, I can display it in html. But I have a problem exporting them in a plain txt file. A string like "элиас" gets "—ç–ª–∏–∞—Å" if I let rails put in in a txt file and download it. Whats wrong here? What has to be done? Regards, Elias ...

Why JavaScript returned another page, when i set new window.location?

Hello, all. Have one a question. When i, for example, on "page 1" page, i have js in html: <% if session[:download_link_for_pricing] %> Event.observe(window, 'load', function() { if (confirm("Download new Pricing?")) { location.href = "<%= session[:download_link_for_pricing] %>"; }...

Generate an image an show it in a html page without write it on the disk

In a my project in Ruby On Rails (but this is not important), when I load a html page, I need to decrypt an image (jpg) and show it in the web page: after the page request, the image is decrypted an the file is write on the server disk, so the browser can show the image. I don't want to write the image on the server, but I want to encry...

How do I read properties from my controller

Hi I am new to rails, and I have no idea how to make properties in a settings file that I can read from my rails application. I have this code: Time.now.advance(:days => -7) I would like it to be configurable, so that I can configure it to be (:months => -2) or what ever I like. How do I do this in rails? Thank you ...

rails: Facebook comments button can't recognize different resources!

Hello everybody, I try to implement a facebook comment box to my catalogue controller. Every catalogue entry should have his one facebook comments! The problem is that the fxml doesn't recognize different resources. www.remme.com/catalogues www.remme.com/catalogues/2 www.remme.com/catalogues/3 This seems to be the same page for faceb...

Rails increase db value by one

Hi, I have a Pages table in my DB with a field called position. How can I increase that value by one before it's saved? Even better how can I remove unused positions and give the new record the correct position number? ...

"Not Available" Rails

Dear All, When I use a table from database, if data is not available in table. I will use if and else conditions like <% if @tables.blank? %> <p> Not available</p> <% else %> blaaa blaa <% end %> It works fine. Now I need to apply the same thing for connected tables. If data is available in first table tables and not available in...

Rails set all record values to zero

Hi, How can I set all records to 0 in a table? -- UPDATE -- What I want to do is the following. I have a table called Pages with an attributed called position. When I delete page from the table i want som function to reorder the positions, so that there wont be any not used positions. EX. Position 1, 2, 4, 8, 9, 12 becomes 1, 2, 3, 4, ...

writing cURL like function in a rails app

Hi guys! I'm trying to convert this PHP cURL function to work with my rails app. The piece of code is from an SMS payment gateway that needs to verify the POST paramters. Since I'm a big PHP noob I have no idea how to handle this problem. $verify_url = 'http://smsgatewayadress'; $fields = ''; $d = array( 'merch...

Rails: Would this go in a helper?

I've currently got this in my view file: <%= "<em>(#{package.to_company})</em>" unless package.to_company.blank? %> Is my understanding correct that I should move that to a helper? ie. def package_company(package) "<em>(#{package.to_company})</em>" unless package.to_company.blank? end I ask because I've got a few dozen unless st...

Can some one summarize briefly what each line is doing here please?

Just got this RoR app working, and just want some clarification to what exactly went on behind the scenes, briefly so I can look into each step: Clone the git repo git clone git://github.com/railsdog/spree.git spree cd spree Install the gem dependencies bundle install Create a sanbox rails application for testing purposes rai...

Rails View Helper Not Inserting HTML into Page

I'm having an issue using a custom helper method in my Rails (3.0) app to output the required html. I have the following call in my partial view: _label.html.erb <% display_resource "Diamond", @resource.diamond %> And in the resource_helper.rb file: module ResourceHelper def display_resource(display_name, value) "<tr><td>...