ruby-on-rails

Ruby On Rails - many to many between the same table

I am trying to create a somewhat complex relationship in Rails, and am having some trouble finding the best way to do so. I have a Users table in which each user acts as a teacher and a student. I would like to have a has_many "students" (which are also just Users) and a has_many "teachers" (which are also just Users). I do not want to d...

How to route Rails URLS with controller & action but no parameters?

Hi folks - new rails user here. I have a rails project that I want to accept a controller and an action, but no parameters. At the moment, the (default) scaffolding-created controller returns the 'show' command whenever I enter an action with no a parameters unless it's the "new" action. If I add a def to the category_controller.rb file...

getting id of parent element in rails rjs

I'm working with a that allows the user to add new contents to a shipment box. For example: The user is setting up a shipment, each shipment can include multiple boxes, and each box can contain multiple contents. So I have link_to_remote connected like: In my shipment box partial: <div class="shipping_box" id="shipping_box"> #so...

Rspec Postgres Error

Let me preface this be saying that I'm newb to both TDD and Ruby on Rails. I'm using Rspec to perform unit testing of my data layer and to ensure that my database is rejecting invalid input. My rspec code looks as follows: it "should fail at saving without name" do @my_data.attributes = valid_my_data_attributes.except(:name) @my_d...

Rails two-way self-referential has_many :through -- controller setup?

In my Rails app, a user can subscribe to other users. One should be able to get a user's subscriptions and subscribers from a user instance. Right now, I have a User model and a Subscription model. Subscription is the join model (joining User to User) in a two-way self-referential has_many :through relationship. Subscription: class Su...

How to search the pre and post part of the word using Thinking_sphinx gem on rails

Hi, I have created my search part successfully with the thinking_sphinx gem and I have searched a word it is showing correct, But the problem with the search is it need full word to be given to search exact match. I dont want to give exact word instead any particular character or part of words also be taken into account. help me to s...

How can i use xml attributes when converting into a hash with from_xml?

I have an xml element with multiple child elements that use the same ID. The child elements are distinguishable by a "size" attribute. When I create a hash using .from_xml it lumps all these child elements 1 field. How do I parse these child elements into different fields based on the xml attribute? XML: <artist rank="48"> <name>KI...

Getting low rails mongrel requests per second (8-15 per second)

So I have tried this out on multiple computers with multiple setups (servers/apps) and I seem to consistently get Rails completing 8-15 requests per second even for doing selects on empty tables with 1 field. I think I'm doing something wrong here because I've read a lot of stats online where people are getting 60-200 with mongrel. So be...

Tests won't run on newly-generated plugin

I'm using Rails 2.3.8. I created a standard plugin running script/generate plugin machine_tags and I'm trying to run the default sample test that comes with it under vendor/plugins/machine_tags/test/machine_tags_test.rb. I go to the plugin directory and issue a rake test, but all I get is this: (in /home/helder/code/shapado/vendor/plugi...

ruby dynamic method passing a value

How do I pass a value to a dynamic method name that's called on a rails model? @model.send(dynamic_method_name.to_sym,123) This gives the error: wrong number of arguments (1 for 0) If I were to use the same method like this though: @model.post_id = 123 then it works. So there is a "setter" method for the method post_id (and t...

How to retrieve the referer in RoR?

I tried request.env["HTTP_REFERER"] but it returned nil. I need to track where the user comes from (external sites) Please help! ...

Rails ignores collection route and goes with show action instead

I have the following routes set up in my routes.rb file: resources :people do collection do get :search end end When i do a get action on the url: http://localhost:3000/people/search.json?term=stepeb, the server reports that it's responding with the show action, with the correct term parameter, but also has an id parameter, s...

How to insert primary key value explicitly?

I have a table called messages and here is the table structure, I don’t want id is auto increment field but it should be a primary key for that table. Here is table structure for messages CREATE TABLE `messages` ( `id` INT(11) NOT NULL, `user_id` INT(11) NOT NULL, `text` VARCHAR(255) NOT NULL, `source` VARCHAR(...

What is Rails' migration equivalent to MySQL's 'double' datatype?

I can't seem to figure this one out by searching Google. I have an existing database which has some columns with the type of double, what would I write in my rails migration to create an equivalent column type? It's a relatively old database and there maybe a more suitable datatype to use completely, but I wanted to see what others thou...

Using a rails partial in a jquery dialog box

Hello, I'm trying to insert a partial into a jquery dialog box. The dialog box is working but no partial.. Here is my code : application.js $(document).ready(function(){ $("#add_note").click(function(){ $("#notes").html("<%= escape_javascript(render(:partial => @note)) %>").dialog({title: 'Basic Dialog'}) }) }) my vi...

How do I do multiple lines of Ruby in html.erb file

Hey, I'm using Ruby on Rails and need to run a block of Ruby code in one of my html.erb files. Do I do it like this: <% def name %> <% name = username %> <%= name %> or like this: <% def name name = username %> <%= name %> Thanks for reading. ...

How to remove previous sessions in Rails, if user forget to logout and close the browser?

I store all session information in database. The user can login the system for do something. There are some restricted area required user login. If the user try to reach those area before login, the system will redirect them to login page. Sometimes user may close the browser without logout. If this happen, next time when he try to logi...

Storing arrays in database using ActiveRecord

I am on rails 2.3.8 & I am using mysql as db adapter. I want to store arrays in my database. After searching I could come up with this very useful article. Now I need to use GUI for input & not only server console. So say I have a text field called nums which logically should have int array. What should be the format of nums so that it...

Insert a Rails remote_function call in a google map infowindow

Hi, I'm trying to add a button to a googlemap infowindow so that when the user clicks on the button ajax is used to update a table of points outside the Map. I can open the infoWindow and add 2 button Save/Delete. Delete simply removes the marker and closes the infoWindow. Outside of the map I've successfully set up the Rails code to...

Google Openid authentication and identification of Domain Admin

I have implemented Google openid authentication for my web application (ruby on rails) , now once authenticated how am i suppose to get the status of that particular user ? like if the user which has been authenticated is a domain admin or not ? i have googled it a bit and came up with Google provisioning ApI and ClientLogin authenticati...