Questions for ruby


1301

Injecting dependencies in Sinatra app

I'm writing a Sinatra app that calls some external services. I want obviously my tests to avoid calling the real services so suppose at the moment I have this
9817

How can I include all eventualities?

This code takes in a 3array (position) and tests to see whether it sits in some region of the model or not. The problem is in the PbSheild method, I can't work out why though. This code will work a...
9729

awesome_nested_set How to not select a parent?

I just got awesome_nested_set put in place and all is working well. I converted over from acts_as_tree using Category.rebuild! listed on the github link.
5005

What is the correct way to setup database with DataMapper and Sinatra on production server?

From the DataMapper document, I think there are at least four functions need to be called to have database setup:
4078

Command to be run when it is terminated by Ctrl+C

Is there a reserved command name that will be run when the entire script is terminated by the user with Control+c? For example, if I wanted to do puts "Script terminated by user." when the script is
8996

Building an HTML document with content from another

I'm have a document A and want to build a new one B using A's node values.
469

Ruby idiom for default values

Is there a better way to write this in Ruby, without writing "bar" twice?
6662

Rails 3.2 Rendering Associated Models in Same Form

i'm working through Hartl. Ive got to the microposts section in Chapter 10, but instead of microposts I have introduced Hotels, and now I want to add them to a separate address model, like in this
3308

Substitute method arguments in Ruby

how to bind a set of arguments to a variable and then use the variable as argument for a method, e.g.
513

Why is ruby responding that I've already mixed in a module when I haven't included it yet?

I have a class Ryte::Theme. If I call included_modules on the class I get back (abbreviated):
967

Intersection of two points in Ruby

I want to find intersection of two points in Ruby. What type of checks should be there so that the function works for all cases.
9218

How to choose a single model and persist that choice?

I have a simple model called Party with a corresponding table called parties. There's also a controller with all the usual CRUD actions and so on. This model is used in a website and only one admin...
7673

Rails model without database

I want to create a Rails (2.1 and 2.2) model with ActiveRecord validations, but without a database table. What is the most widely used approach? I've found some plugins that claim to offer this
7810

Rails won't save to database after tiny model manipulation

I'm coding my first Rails app at the moment and can't resolve this annoying error.
2817

How do I run a rake task from Capistrano?

I already have a deploy.rb that can deploy my app on my production server.
5171

Why does Ruby “script/generate” return “No such file or directory”?

I am having trouble using script/generate. I am following the tree based navigation tutorial, which says to use script/plugin install git://github.com/rails/acts_as_tree.git or script/generate
958

RDoc : Change name of 'Atttributes:' section in ri-documentation

I'm using some meta-programming to generate a bunch of methods in ruby like so:
4567

How do I create an interactive menu in a terminal?

I'm trying to build an terminal application that, when started, will take the user away from their prompt and present them with a screen with an interactive menu. I would like the user to be able to
9816

Ruby UTF8 encoding problem

I have a Ruby/Rails app.
8800

What does -> mean in Ruby

I've seen that in spree commerce.
608

Unable to access unescaped html in an RSS feed

I'm using the built in RSS capabilities of Ruby (RSS::Parser.parse) in a new rails app. The app reads several different sources of rss feeds that are outside of my control (public facing, built by
2982

Ruby on Rails: Entering data from another database into a new database

I have two databases in my app. One is Projects, that holds data on projects created in the app and another is User that I made when installing the Devise gem that holds the usernames and passwords...
1978

Cannot rescue error in Rails application

I am creating an application where a user logs into an Oracle Database and runs prepared queries. I would like to use ActiveRecord to help run the queries, but I am running into some issues.
3252

how to place YAML inside a YAML document

I am working with Rails fixtures for testing my rails application. It is all good except one of my database columns is supposed to hold YAML content. But, I am sure how to put the YAML markup I w...
5178

Run a php script in ruby on rails

In one of my Rails application I need to execute a PHP file from the Controller of Ruby on Rails app. The PHP file meant for some database editing.
5461

Rails mysql update

I'm pretty new to Ruby on Rails, I came from PHP and i've realised it's not just as simple as getting syntax down, there's a lot of good structure practices to take on board too.
9356

Rounding a float to the nearest integer in ruby

If i have a float of 49.967 and I do .to_i it will chop it down to 49 which for my use of disk space analysis .967 is over 900mb of space that wont be accounted for in the displays.
9113

Scripting language choice for initial performance

I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution...
5670

what is the proper syntax for seeding a child table?

I'm trying to seed a parent table and a child table. Seeding the parent works fine but I don't know the syntax for seeding the child. Please help.
3249

Update a boolean field in db using link_to

I have boolean field in the database, how can I update it in rails using link_to. I want to have two link_to commands. One for true another for false.
8292

Rails ActiveRecord::Migration - writing a textfile contents to the database

I'm doing something slightly unorthodox here, in that I'm just populating the database via a migration, and using the contents of a textfile. I'm using the following method which doesn't import the
7494
5272

Difference between p in a rails view and puts

I am a newbie in Rails. I created a controller and a action. In the corresponding view I used
8639

Ruby send string variable as hex

How am I to express variable as hex to send like-
5520

Can I define_method in rails models?

My rails model has code that is attempting to define_method(method_name) inside the model.
7024

Trying to populate gmaps4rails with multiple json strings in one page

I hope I am asking this right, so please let me know if I'm way off.
7731

why am I getting a mass assignment error when my column is on my attr_accessible list

There are several related questions to this one. But none of the answers address my situation.
2097

Error calling Javascript in Camping App

I want to learn about webapps. I decided to learn by doing and chose to start simple with Camping as (i). it is small & (ii). i know some ruby.
383

How to design a class which has a list of boolean variables?

I have a Ruby class called Category which has various boolean values like
3783

Union two mongo results

I have a situation where I need to return a single collection of objects from mongo, but need to use two queries to get the results. The order of these results is important because they are paginat...
1189

How can I put (parts of) a large object graph in Rails.cache?

I have a class in which looking up an instance is expensive, so instances are cached:
6072

Ruby: until a new object has some property

How can I refactor the following code to avoid repetition?
1201

How to initialize custom ActiveModel Validators in Rails 3+ app from within a Rails Engine

I'm trying to load some custom Validators from a Rails Engine but my application keeps failing due to the validator not being recognized.
8891

Forwarding requests UDPSocket

I have a basic ruby program, that listens on a port (53), receives the data and then sends to another location (Google DNS server - 8.8.8.8). The responses are not going back to their original

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.