ruby-on-rails

Read contents of a local file into a variable in Rails

All I want to do is get all the content from a local file and store it in a variable. How? File.read(@icon.full_filename).each {|l| r += l} only gives me a part of it. In PHP, I just used file_get_contents. Thanks! ...

Ruby on Rails: Cucumber: how do I replace text in a field?

I want to put text into a field that has been autofilled. The traditional When I fill in "ntoheu" with "nthoeu" seems not to work Iam also using capybara, and i feel that its ability to successfully insert text into fields is lacking. ...

how to disable select option in rails ?

<%=f.select :action_item_status,action_item_status%> How can i disable all the option in this select option. ...

Ruby on Rails - Rake task not working through Cron

When I execute a rake task manually, it works fine but when I put the same command in Cron nothing happens: cd /path/to/my/rails/app && rake daily_import The Cron log indicates that the command was issues: CMD (cd /path/to/my/rails/app && rake daily_import) The rake task logs error and success messages, but nothing is recorded to the...

I get "stack level too deep" error when using a named scope

I'm using ruby on rails 2.3.8 and when I write the syntax shown below I get the "stack level too deep" error message. The model is called Announcement and the line of the error looks like this: Tag.find(category_id).announcements.published Where published is named_scope :published, :conditions => "announcements.state = 'published'"...

Restrict a number to upper/lower bounds?

Is there a built-in way or a more elegant way of restricting a number num to upper/lower bounds in Ruby or in Rails? e.g. something like: def number_bounded (num, lower_bound, upper_bound) return lower_bound if num < lower_bound return upper_bound if num > upper_bound num end ...

Access Ruby on Rails 'public' directory without relative path

I have a flash object I wish to load and I belive the best place to store that asset is in the public directory. Suppose it's stored in public/flash, there must be a better way to path to the swf than what I've done below. Note the 'data' element, it has a relative path. def create_vnc_object haml_tag :object, :id => 'flash', ...

Ruby on Rails when create method fails, render loses local variables

Hey guys I have a simple create method with some validations and whenever the create method fails due to validation errors it re-renders the 'new' action. The problem is in my new action/view I have a local variable that is established in the action and passed to a partial to render some related information to what the user is creating....

best ruby on rails cms

i need to choose a cms for my next project, i have searched and come up with these 2 : radiant and refinery, which one is better for building middle size websites ? are there any other options out there for rails cms ? one important factor is that client can easily update their website without much knowledge thnx for helping ...

Access Models from OUTSIDE rails app

I am writing a JRuby rails app that uses mysql-backed models. Now, I need to update the models from OUTSIDE the app (via EventMachine / similar), so that the Controllers etc IN the rails app can get access to the fresh data. So, is the Rails ORM available inside EventMachine? Will there be catastrophic consequences if I update the mysq...

rails + ActiveRecord: caching all registers of a model

I've got a tiny model (let's call it "Node") that represents a tree-like structure. Each node contains only a name and a reference to its father: class Node < ActiveRecord::Base validates_presence_of :name, :parent_id end The table isn't very big - less than 100 elements. It's updated rarely - in the last 4 months 20 new elements we...

Appropriate implementation for delegated HMAC API auth?

My team and I are implementing a centralized API authentication system so that one set of API credentials can be shared among several different API-publishing services. These are all Rails apps. Long explanation For any given API transaction, there will typically be 3 apps involved: End-user-facing app that consumes API X. Has API ...

How do I set up my @product=Product.find(params[:id]) to have a product_url?

Trying to recreate { script/generate scaffold }, and I've gotten thru a number of Rails basics. I suspect that I need to configure default product url somewhere. But where do I do this? Setup: Have: def edit { @product=Product.find(params[:id]) } Have edit.html.erb, with an edit form posting to action => :create Have def create { ... ...

Rails: How to name and create unique divs within a loop?

I have a view with a div that is looped many times. Each of the created divs need to have a unique ID so I can access them specifically (at the moment, all my divs have the same ID specified in html so whenever I try to access a specific div it just finds the first one). This is the version that I currently have (multiple 'rowBox'es are...

Rails 2.3.x use bleeding edges gems

In rails 3 you can use bleeding edge gems like: gem "devise", :git => "git://github.com/plataformatec/devise.git". How do you do that with config.gem in rails 2.3.x? ...

How to apply a scope to an association when using fields_for?

I have a Project having many Tasks, and each Tasks belongs to a Person. In my Project edit form, I permit to edit existing tasks and add new ones with the Nested Object Form facility (http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes): <% project_form.fields_for :tasks do |task_form| %> I want to eage...

Convert SQL query to Ruby help

Hey all, I need to query my database table to find which employee has the most support tickets related to them. I can do this just fine using this MySQL query: SELECT employee_id, COUNT(id) AS number_of_tickets FROM tickets GROUP BY employee_id ORDER BY number_of_tickets DESC LIMIT 1; How would write this in Ruby-on-Rails? Thanks v...

Where to do an HTTP request when a model changes and be able to send a url to access it with the request

I'm trying to implement a PuSH Publisher on rails. To do that I need to send an HTTP POST request to another server (a PuSH Hub) when my model updates and one of the parameters is a url to my feed (the model that changed). Where in rails (in the MVC) am I able to do this request when my model changes and can build the url to the changed...

How to add delay to ruby on rails controller redirect

Hi, I'm pretty new at rails and have an app where the user has to "turn-on" a script. I have this code in the view: <% if @robot.thread_status == "" || @robot.thread_status == nil %> <b>Status: <font color ="red">NOT MONITORING</font></b> <br> <% if @robot.recipients.present? %> <%= link_to 'Start monitoring th...

Caching Models in rails

I have a rails application, with a model that is a kind of repository. The records stored in the DB for that model are (almost) never changed, but are read all the time. Also there is not a lot of them. I would like to store these records in cache, in a generic way. I would like to do something like acts_as_cached, but here are the issu...