ruby

Rails best practice for having same form on multiple pages

I am developing an Rails 2.3.1 Web site. Throughout the Web site, I need to have a form for creating Posts on various pages (Home page, Create Posts page, Post listing page, Comment listing page, etc. -- suffice to say this form needs to be on many pages served by a variety of controllers). Each of these pages displays a wide variety of ...

Passing a blank XSD::QName using soap4r

I have overridden the SimpleHandler to pass a username and password using soap4r. the problem is that I am forced to give a QName, and this is causing the result to fail because it's not in the right format. What soap4r is adding is something like this (the "ns1" things are dummy values): <env:Header> <n1:ns1 env:mustUnderstand="0" ...

Building multi-line strings, programatically, in Ruby

Here's something I often do when programming: code = '' code << "next line of code #{something}" << "\n" code << "another line #{some_included_expression}" << "\n" Is there some better way than having << "\n" or + "\n" on every line? This seems quite inefficient. I'm interested in Ruby solutions, in particular. I'm thinking something...

Why does string + fixnum addition generate coercion error?

Why does ruby addition cannot coerce given string to fixnum and vice verca? irb>fixnum = 1 => 1 irb> fixnum.class => Fixnum irb> string = "3" => "3" irb> string.class => String irb> string.to_i => 3 irb> fixnum + string TypeError: String can't be coerced into Fixnum from (irb):96:in `+' from (irb):96 from :0 irb(main):097:0>...

Ruby on Rails: Equating items in controllers (or maybe models?)

I'm trying to make attributes equal predetermined values, and I'm not sure if I'm doing that efficiently with the following (in my orders controller): def create @order = Order.find(params[:id]) @order.price = 5.99 @order.representative = Product.find(params[:product_id]).representative @order.shipping_location = SHIPPING_LOCATI...

I have a problem in linking a stand with two checkboxes owner communication and resident communication.

I have a problem in trying to link a stand with two checkboxes which are resident & communication, and they seem to be stored separately if more than one stand is choosen. If I have one stand the parameters seem to be stored in the correct manner inside a hash of an array, but once I add another stand to that same array it seems to swap...

The Authlogic record method. What does this do

I came across this method called record that Ryan bates uses in his authlogic Railscast and can't seem to understand what it does. I have been through the documentation but I can't seem to follow how that helper is useful. def current_user return @current_user if defined?(@current_user) current_user_session && current_user_session....

Delete hidden files in Ruby

Does anyone know how to delete all files in a directory with Ruby. My script works well when there are no hidden files but when there are (i.e .svn files) I cannot delete them and Ruby raises the Errno::ENOTEMPTY error. How do I do that ?? Thanks in advance. ...

How to find the local port a rails instance is running on?

So I would like my Rails app instances to register themselves on a "I'm up" kind of thing I'm playing with, and I'd like it to be able to mention what local port it's running on. I can't seem to find how to do it - in fact just finding out its IP is tricky and needs a bit of a hack. But no problem, I have the IP - but how can I find wha...

Understanding the "||" OR operator in If conditionals in Ruby

Just briefly, why are the following three lines not identical in their impact? if @controller.controller_name == "projects" || @controller.controller_name == "parts" if @controller.controller_name == ("projects" || "parts") if @controller.controller_name == "projects" || "parts" The first gives me the result I want, but as there's a...

Scrubyt fetch metadata

How to fetch the contents of meta name="description" content="....." with Scrubyt ? require 'rubygems' require 'scrubyt' data = Scrubyt::Extractor.define do fetch 'http://www.allegro.pl/' head '//head' do description '//meta[@name="description"]' end end puts data.to_xml What is the the correct way ? ...

How do I tell Ruby's OpenSSL library to ignore a self-signed certificate error?

I'm trying to use Ruby's SOAP support as follows: SERVICE_URL = 'https://...' ... def create_driver ::SOAP::WSDLDriverFactory.new(SERVICE_URL).create_rpc_driver driver.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE driver.options['protocol.http.ssl_config.client_cert'] = @certificate_path driver en...

Where can I get a Ruby 1.8.6 for Centos OS

Hi. Can anyone tell me where I can find a Ruby 1.8.6 so I can istall it in my Centos 5 machine? Thank you. ...

How to do a regex search in nokogiri

given: require 'rubygems' require 'nokogiri' value = Nokogiri::HTML.parse(<<-HTML_END) "<html> <body> <p id='para-1'>A</p> <div class='block' id='X1'> <h1>Foo</h1> <p id='para-2'>B</p> </div> <p id='para-3'>C</p> <h2>Bar</h2> <p id='para-4'>D</p> <p id='para-5'>E</p> <div class='block' id='X2'> <p id='para-6...

How can I remove duplicate XML nodes using Ruby?

Suppose I have this structure: <one> <two> <three>3</three> </two> <two> <three>4</three> </two> <two> <three>3</three> </two> </one> Is there anyway of getting to this : <one> <two> <three>3</three> </two> <two> <three>4</three> </two> </one> using Ruby's libraries? I managed to...

Please help rails problem with stringify_keys error

I have been trying to solve this for ages and can't figure it out. I have a form like so (taking out a lot of other fields) <% form_for @machine_enquiry, machine_enquiry_path(@machine_enquiry) do|me_form| %> <% me_form.fields_for :messages_attributes do |f| %> <%= f.text_field :title -%> <% end %> <%= me_form.submit '...

Login to online accounts

First time poster. Back to programming after being away for a few years, trying to clean off the rust. I'm creating a dashboard that will run initially on my laptop (Macbook Pro, 10.4.x O/S). Amongst other things I want it to retrieve latest information from my online accounts. I'm starting with html, but will probably migrate to som...

Verifying Resftul Authentication through a Non Ruby App

I'm trying to do Authentication against restful_authentication from a php application, however I understand it uses a SHA1(digest--salt--password--RESTFUL_AUTH_KEY). The issue is regardless of how much I try I can't get the hash to match. Reading through the documentation I see the digest is just the restful auth key, but that's where I ...

What separates a Ruby DSL from an ordinary API

What are some defining characteristics of a Ruby DSL that separate it from just a regular API? ...

Raw POST from Ruby on Rails

I'm trying to do a raw POST to an internal page from a unit test, and for some reason I'm getting the following error: NoMethodError: undefined method `symbolize_keys' for #<String:0x258a910> unit/call_route_attempt_test.rb:10:in `test_response_from_call_info' My code looks like this: post :call_info, '<?xml version="1.0" encodi...