ruby

Ruby gem error installing rack-mount + Rails

I would like to install Rails 3.0 Beta but ran into what appears to be a dependency error: $: sudo gem install rack-mount Successfully installed rack-mount-0.5.1 1 gem installed Installing ri documentation for rack-mount-0.5.1... Installing RDoc documentation for rack-mount-0.5.1... $: sudo gem install rails --prerelease ERROR: Erro...

How can I convert this code to meta-programming, so I can stop duplicating it?

I've got a small but growing framework for building .net systems with ruby / rake , that I've been working on for a while now. In this code base, I have the following: require 'rake/tasklib' def assemblyinfo(name=:assemblyinfo, *args, Albacore::AlbacoreTask def execute(name) asm = AssemblyInfo.new asm.load_config_by_ta...

Does ruby have a log viewer?

Is there a log viewer for displaying Ruby log files from any of its loggers (be it l4r or their basic logger)? Some kind of gui app that opens a log file and can support simple queries such as INFO only? ...

How to include a YAML file inside a YAML file?

Is there a custom tag in YAML for ruby to include a YAML file inside a YAML file? #E.g.: --- !include filename: another.yml A similar question was asked some time ago and there was no relevant answer. I am wondering if there is some custom tag for Ruby similar to this one for Python. ...

next verus if in a .each loop?

Hello, I have a text processing thing I'm doing in Ruby. Basically, I have to implement a simple state machine(with one character look-behind My code at the moment looks like this: text.each{ |c| ... ... ... ... if @state!=:some_state next end #processing stuff for if in :some_state mode ... ... ... ... ... ...

Why do so many gems end in fu?

Why do so many gems end in fu? Not that this make it clear to me, but here is what Google says "define: fu". ...

setting a global within a proc

I've been working on trying to better understand Ruby and here's something I'm having trouble with: $SAFE = 1 puts $SAFE # 1 proc { $SAFE = 2 puts $SAFE # 2 }.call puts $SAFE # 1 The above code is partially taken from eRB's source rewritten to better highlight the example. Basically within the proc one can set the value of $...

Timer in Ruby performance

Hi all, I was looking for an online example demonstrating a timer in ruby and came across the code below. It works as expected but does it make sense that this simple program uses 30Mo of memory (as shown in windows task manager) and way too much CPU? Thanks a lot def time_block start_time = Time.now Thread.new { yield } Time.now...

Authlogic and multiple sessions for the same user

Hello, I'm using Authlogic to manage the sessions in my application. However, by default, authlogic allows a user to be logged in many times from different computers. I don't want that (the user pays to get access and I want to avoid users sharing their accounts). Looking in the Authlogic documentation, I've found about the perishable_...

How can I create a nokogiri case insensitive Xpath selector?

I'm using nokogiri to select the 'keywords' attribute like this: puts page.parser.xpath("//meta[@name='keywords']").to_html One of the pages I'm working with has the keywords label with a capital "K" which has motivated me to make the query case insensitive. <meta name="keywords"> AND <meta name="Keywords"> So, my question is: W...

collection_select and not being submitted database

I have a small problem and it is really bugging me. I have all the standard scaffold code in the controllers to give me the standard CRUD features. The collection_select form helper is in my view: <%= collection_select(:link,:category_id,@categories,:id,"name") %> The Link Table has a category_id column. This is being posted ok,...

Breadcrumbs in Ruby on Rails

Hi, I'm slightly insecure about my breadcrumb solution. Names and links are defined in each controller action: <a href="http://localhost:3000/"&gt;Home&lt;/a&gt; <% if defined? @l1_link %> > <a href="<%= @l1_link%>"><%= @l1_name %></a> <% if defined? @l2_link %> > <a href="<%= @l2_link%>"><%= @l2_name %></a> <% end %> <% end ...

Constant in class << self block

In the following fragment, is it possible to refer to the FOO constant from outside the module, and if so, how? module X class << self FOO = 2 end end ...

How to add a custom log level to logger in ruby?

I need to add a custom log level like "verbose" or "traffic" to ruby logger, how to do? ...

Authlogic and declarative authorizsation

Hello, I have a rails application based on Authlogic with LDAP for authentification, and declarative authorization for roles requirements. The problem is when i put filter resource_access in my controller, i got this error : undefined method `current_user'.... I had define the method current_user on the application_controller Any hel...

Ruby equivalent of C#'s 'yield' keyword, or, creating sequences without preallocating memory

In C#, you could do something like this: public IEnumerable<T> GetItems<T>() { for (int i=0; i<10000000; i++) { yield return i; } } This returns an enumerable sequence of 10 million integers without ever allocating a collection in memory of that length. Is there a way of doing an equivalent thing in Ruby? The specifi...

I can't get the ruby development kit working for Windows XP

So, I can't for the life of my get this working properly. My ultimate goal is to get the dbd-odbc gem installed and working, and from multiple things I've read, I need to install the ODBC binding for ruby alongside the dbd-odbc gem. Well, I can get the dbd-odbc gem installed just fine, but when it comes to trying to install the binding i...

How to access the joining model on a has_many :through relationship

I have a typical many-to-many relationship using has_many => :through, as detailed below. class member has_many member_roles has_many roles, :through => :member_roles end class role has_many member_roles has_man members, :through => :member_roles end class member_role belongs_to :member belongs_to :role # has following f...

Rails Custom Deprecation Notices

Is there a way to create custom deprecation notices for methods and/or associations in my application that I plan on removing and want to log their usage? I have a relationship in one of my models that I don't want to use moving forward and plan to refactor the code at a later time. I would like to create a notice in my development log e...

Rails accessing a view partial via the browser url

I've got some javascript that needs to load a rails partial - I'd prefer not to repeat the partial's HTML in the javascript file. Is there a way to make this partial accessible via the browser url so JS can load it? partial location: shared/_search.html.erb I would like to grab the view html with something like this: example.com...