ruby-on-rails

Need help with design of a Rails 2 app having two partitions

I have models A,B,C,D, etc. I have my usual controllers/views/helpers for each of these models. These are accessed by a set of content authors in a form based application to populate data into the db. The content authors will also have categories like authors, publishers, super admins etc. Essentially we have built out a mini content man...

Rails LDAP login using net/ldap

I am trying to get LDAP authentication to work under Rails. I have chosen net/ldap since it's a native Ruby LDAP library. I have tried all possible stuff, specially examples from http://net-ldap.rubyforge.org/classes/Net/LDAP.html but still unable to get it work. Any ideas? ...

optimistically save session in authlogic

I am trying to create similar functionality as this gem authlogix-rpx, which optimistically saves the session/user object even if some of the validated fields are missing. http://github.com/tardate/authlogic_rpx/tree/master/lib/authlogic_rpx (line 167) With this gem it's possible to create the record that does not meet validation crit...

how do i use delayed_job on heroku to send out emails that are batched?

Hi, I read the documentation on workers and delayed_job and couldn't follow exactly, so wanted to get head-start with some strategy and sample code. I have a controller which I use to send emails one by one. Now each day I want to check which emails need to be sent for the day, and then send them through heroku as a delayed_job. How ...

sending json response

I'm sending a request from jquery and expecting json response. Configuration is like this: type: 'POST', cache: false, iframe: true, dataType: "json", Now there's a funny thing. When I return data as text, it works fine: render :text => "{}" But when I use :json option, firefox prompts me to down...

Rails + Haml: How to unescape tag parameter?

I'm trying to accomplish the following content in source code: <div id="box<%=id%>"></div> Without escaping any signs in Haml. %div{ :id => "box_<%=id%>" } produces <div id='box_&lt;%=id%&gt;'></div> Right now the only way I can do this with Haml is to use :plain filter and hardcode HTML without using any View Helpers. How can I...

Why is my OpenId authentication failing?

I'm porting my OpenId authentication scheme from Sinatra to Rails 2.3.8. Everything works well up until I get the response back from my OpenId provider. The Response object I get back is an OpenId::Consumer::FailureResponse, when it should be a SuccessResponse. I ported this directly from Sinatra, and the only difference is what sessio...

Get 10 Random Records From SQLite Database

I haven't been able to find a very good way of getting 10 random records out of a sqlite database. Seen a few examples that work with mysql, but they don't seem to work well with sqlite even though I am trying to us Random() instead of rand(). I have tried to get random numbers and then get the records by id, but for some reason I am ge...

Ruby class-level instance variable

So I was doing a refresher on Ruby and I saw this guy's blog about creating class-level instance variable in Ruby. I am still trying to understand what the code actually does here. His blog can be found here http://railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/ and I have created a simple code based on his...

Why is my Controller/Action not responding to a :put?

I am trying to follow the rules and stay RESTful, but I am running into some problems. I set my routes so I am sure it is calling the right action, when I run rake routes this comes up: PUT /admin/settings {:controller=>"admin", :action=>"save_settings"} So I know my route is correct, and in my *views/admin/settings.html.erb" I hav...

Constructing sql in ruby on rails

The following SQL I am trying to run is returning sql_string of "SELECT id FROM people WHERE id IN ("16")": @ids = ["1", "6"] sql_string = <<-SQL SELECT id FROM people WHERE id IN ("#{@ids}") SQL Can someone please help modify the above query so it will create the sql_string of "SELECT id FROM people WHERE id IN (1, 6)" ...

How to freeze Facebooker gem?

I tried rake gems:unpack, it worked for most gems, but facebooker gem doesn't get frozen. How to freeze it? Thanks ...

Get join model from has_many_through relation

Hi, In my Rails app I have a has_many_through relation. I want to use the join model/table to store some data about the relation (how many times that particular relation is used, to be specific). I'm writing an add-method on one of my classes which should check for any existing relation with the subject, update a counter on the relatio...

Installing Ruby on Rails on Windows 7 - quick and easy

Since I had so many issues installing RoR on my laptop with Windows 7, I thought I would share my steps with you. Many people tell you to use InstantRails. I did that one too, but the option below worked best for me. Download and install Ruby 1.8.7 http://rubyforge.org/frs/download.php/71492/rubyinstaller-1.8.7-p299.exe Download the l...

Where can I get a list of possibilities in migration classes?

i I am new to rails and ruby. I am trying to make a ActiveRecord::Migration to match my wishes, but where can I find documentation for what is possible in a ActiveRecord::Migration? I mean how to define field lengths for e.g. string and if null values are allowed or not and how to define/create different indexes? Thank you Søren ...

Make rails resource system decide the context for an entity

I would like some suggestions on how to do this the best way: I have a Rails application that handles comments. Each comment belongs to a context, such as a forum topic, or an image. The context reference is polymorphic. I have partial that displays the comment, and that partial also holds links to edit or delete it for example. The li...

Rails app with multiple page layouts - how to DRY up?

I have a Rails-based site with a basic two-column layout. On the right is a sidebar with different (let's just say) vertical widgets. Depending on what page you visit, the widgets can be included, excluded, and in different order. For ex: Main Page (Application) PAGE CONTENT... SIDEBAR Widget A Widget B Widget C Page X PAGE CO...

RoR - How to obtain an access token for the facebook user using OAuth ?

i want create something like "link_to" which can link to "request for permission" in facebook, so if user click "allow" then redirect to my site and i can get their data. my question is how to create a "link" like that? so i can get access token from facebook user. (i had register my app) thx.. ...

before_destroy is not firing from update_attributes

I have a student that has many courses. In the student#update action and form, I accept a list of course_ids. When that list changes, I'd like to call a certain function. The code I have does get called if the update_attributes creates a course_student, but does not get called if the update_attributes destroys a course_student. Can I get...

How can I write a test for this ajaxious form?

I have this form and in it I have this: <%= f.select(:category_id, categories_for_select) %> <%= f.select(:subcategory_id, options_for_select(["Choose category"])) %> Then, when the user change the category the subcategories select box fill itself via ajax. Both of the category and subcategory are mandatory for my model and included ...