ruby

Rails action response should behave like a simple file response - no session or cookies

I have a rails controller I dont ever want to set a cookie. I production, all it's actions are basically page cached and served as static files. But in development it's responses are generated on each request so that we can change things on the fly and test it out. The problem is that when we have parallel requests that change cookie d...

How to cancel scheduled job with delayed_job in Rails?

Title says it all basicly. I am scheduling a job to run in say, 10 minutes. How to properly cancel this particular job without using any kind of dirty extra fields in model and so on. Is there any call to remove particular job, or jobs related to specific model, instance, etc? ...

Ruby/Rails - Problem to build a method with request.fullpath

Hi, I'm trying to build a method in order to add a specific css class to my nav menu on current pages. Here is my start: (in application_helper) def menu_links(param) if request.fullpath == "#{param}_path" return "#{param}_path" end end in my app view: <%= menu_links("help") %> However, if I change request.fullpath == "#{par...

Can i use rak command inside rake task ?

I have install gem rak i want to use rak command inside rake task ... How may i use that ?? I know how to use it on command prompt ... This is working fine on command prompt ... rak RAILS_ENV ...

Do Ruby objects have a size limit?

I'm building some large strings which have a short lifetime within the application. Will the String objects grow arbitrarily large up to the physical limits of the ruby instance? What I'm wondering is if, without any intervention in limiting the string size, my application would get hosed by running out of memory, or whether it would...

rails nils in a form

This is probably a simple question, but I noticed a few errors deriving from having empty values instead of nils... If a user leaves a field blank in a standard rails app is there a way to leave the field in the database set to NULL instead of entering an empty value? Basically so a check like @model.info.nil? return true instead of ha...

Voting update on Ruby on Rails

Right now, I'm in the middle of building a social media app on Ruby on Rails, i have implemented a 5 point voting system. Where you can vote the news posted on the site from 1-5, what I'd like to know is, What is the best approach at handling the updates on the voting system. In example. If a user already voted in an article I'd like to...

Use Nokogiri to get all nodes in an element that contain a specific attribute name

Hi, I'd like to use Nokogiri to extract all nodes in an element that contain a specific attribute name. e.g., I'd like to find the 2 nodes that contain the attribute "blah" in the document below. @doc = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML <body> <h1 blah="afadf">Three's Company</h1> <div>A love triangle.</div> <b b...

Ruby: Declarative_authorization polymorphic associations

I have two models (Item and Theme). They are both owned by a third model Users with a has_many association (User has many Themes and Items). Both Item and Theme have_many :images. The Image model is a polymorphic association so the table has the columns imageable_id and imageable_type. If I had both an Item with ID 1 and a Theme with ...

Installing native Ruby extensions on Windows for Jekyll

Hi Guys, I'm about to go crazy here so I'll just ask: How the hell do you install the Ruby Gem Jekyll on Windows. Jekyll depends on fast-stemmer-1.0.0 and that has to be built as a native extension I found this handy guide on RubyDevKit to install a 'sane' environment on Windows and it works, but fast-stemmer is still hell bent on us...

The fastest best language to develop a fully featured web app.

Hi, I consider myself as skilled programmer and know a large number of languages. Eg Fortran, C, Ruby, Python, PHP, VB, Obj-C, C# etc. I want to build a fully featured piece of Web Based software that would have the following modules. 1. Calendaring System for managing bookings. 2. Record keeping and notes system to record details abou...

Does anyone have experience with Ruby in Steel?

Coming primarily from a .NET background, I am quite attached (for better or worse) to Visual Studio. I'm going to school for software engineering now, though, and my first class is in XP (Extreme Programming) using Ruby on Rails. Mostly I've heard that when you're developing in Ruby, you tend to skip the whole IDE altogether; and I'm to...

rake background task can not run

I want to use rake background task in rails like this system("cd #{Rails.root} && RAILS_ENV=#{Rails.env} rake abc:def --trace 2>&1 >> #{Rails.root}/log/rake.log &") This is ok in development environment, but will not work in production mode. I used logger to check whether the command string is generated ok or not, but it seems every ...

Sinatra, Rails and Rack - User/Session Management

Does anyone know of a way to authenticate in a Rails application and allow other Sinatra applications to pass that authentication token and session state through rack? I'm looking for something that basically allows single sign on. (I already have the secret and key in the rails app with authentication, now looking to use that as the si...

Rails select random record

I don't know if I'm just looking in the wrong places here or what, but does active record have a method for retrieving a random object? Something like? @user = User.random Or... well since that method doesn't exist is there some amazing "Rails Way" of doing this, I always seem to be to verbose. I'm using mysql as well. ...

How to stop a rails controller from executing?

I have the following piece of code def show unless logged_in? login_required return end #some additional code #that should only execute #if user is logged in end This works perfectly. Now I'd like to move the login check into a before filter. The problem is, that when I return from a method outside of s...

Ruby/Rails content_tag isn't rendering correctly (ruby 1.9.2)

Hi, Here below the start of my menu_builder method in the applicationhelper (in the view: <%= menu_builder(@page); %>): def menu_builder(page) items = [ "home", "faq", "store" ] content = "" items.each do |i| content << content_tag(:a, "#{i.capitalize}", :href => "/#{i}" ) end return content end I would like to render l...

Get the html from a website with ruby on rails

How do I get the page data of an other website somewhere on the web with ruby on rails? ...

Ruby print out a float with optional digits

Hi all, I'm trying to print out a float number, that has the value 5 What I get when it print it out is 5.0, so my question is: How to i make it so, that if the value is just 5, it will just print 5 without the .0 after it, and if it is 5.2 or so, it will print out that? I've looked around, but all I found was to either force it one ...

Can optparse skip unknown options, to be processed later in a ruby program?

Is there any way to kick off optparse several times in one Ruby program, each with different sets of options? Example: $ myscript.rb --subsys1opt a --subsys2opt b here, myscript.rb would use subsys1 and subsys2, delegating their options handling logic to them, possibly in a sequence where 'a' is processed first, followed by 'b' in s...