ruby-on-rails

Finding Uploads in Parameters on Submit in Rails

I'm trying to figure out which of these parameters contains an uploaded file. This code works params[:upload].each do | uploaded_image | if (uploaded_image[1] != "") # do something with uploaded_image[1]; end end but my way of moving through the parameters (with the [1], for instance) seems wrong. What's the right wa...

Link_to method and onClick event in Rails

Hi there. I have a small problem. How to create a link of this type: a href="#" onClick="document.getElementById('search').value=this.value" using method 'link_to' in Rails? P.S. I write http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html, but I can not imagine how to make such a link. ...

Autofill IDs in a form with a relation

I have created a blog, it will have posts, and the posts are created by the users. I already have a login system in my blog. And I have made the relation between a user and his posts. Now when I want to add a new post I want Rails to autofill the user_id field. Should I add a hidden field and add the user_id from the session where I sav...

what would happen if you use belongs_to without having a corresponding has_one?

I have a core model for an Item, and a script to populate it from a custom source (think, RSS feed). In the feed, each Item is identified with a guid; in my system, Item only has an autogenerated id primary key. I want to have, let's say, ItemFeedInfo that maps guid->id (so that I can distinguish between new vs. modified Items) I'm thi...

Rails how do I - export data with send_data then redirect_to a new page?

I have a rails app that allows a user to download a generated CSV file. After the file is downloaded, I'd like to redirect the user to a new URL or action. Is there a trick to do a redirect after a send_data? I want to do something like this (which doesn't work): send_data(output,:type => content_type,:filename => "myfile.csv") redire...

Rails' collection_select helper method and the "Create item" option at the end

Is it possible to add an <option> at the end of a <select> created with the collection_select helper method? Right now I have f.collection_select(:category_id , @categories, :id, :name, {:prompt => 'Please select a category'}) which generates <select id="product_category_id" name="product[category_id]"> <option value="">Please se...

Is it possible to have a database transactions span multiple requests in rails?

Hello, I have a form which spans multiple pages. The way it is set up now is not ideal because it saves (to the database) each page when it is submitted. So if the user does not complete the form across all pages there would be an incomplete user registration saved in the database. I would like to 'rollback' the saves if the user doesn'...

Using Google Gears with Rails

I have been tasked with exploring the possibility of offline access of my webapp. What are people's experiences using google gears with rails? I am aware of the gearsonrails project, but it has some really strange constructs and doesn't appear to be under significant, active development. Are there other options? Has anyone added gears t...

how to consume wcf service with ruby?

i have a rails app must consume wcf services provided by asp.net, are there any ruby clients for wcf? ...

Polymorphic association

If you have polymorphic belongs_to associations then references will add both of the columns required: create_table :products do |t| t.references :attachment, :polymorphic => {:default => 'Photo'} end will add an attachment_id column and a string attachment_type column with a default value of ‘Photo’. What, exactly, does this mean?...

Reversed has_many in Rails

Let's say I have models: User and Item and relation many-to-many between them. How to get Users who have exactly(no more) Items with the defined attributes i.e. Users who have Items with colors = ['red', 'black']. Of course I can do something like this: User.all :joins => [:items, :items], :conditions => {:"items.color" => "red", :"...

How can I add Facebook Pages as users to a Facebook app?

I am working on an app that can be added to both user profiles and pages. This screencast showed how profile ID’s can be added to a users table as facebook_id fields, but how can I do the same for page ID’s (the fb_sig_profile_user param)? I have an idea how to accomplish this but I’m not sure if it will work: In the Facebook Pages Set...

Problem adding item to sortable list

I'm not entirely sure how to post this question, but here goes... I have a web app that has a list of sortable items. I sort them ajax style using Sortable. That works like a charm. I can drag and drop the items till my heart is content. At the same time, there is a button that allows for the creation of new items on my list. This ...

Stackoverflow-like login system in Rails?

What's the best (easy) way to implement a login/authentication system on a Rails web-app that looks and works like the Stackoverflow system? I realize that it's basicly OpenID, but Stackoverflow handles integration with multiple providers. Is there a easy way to this on Rails? Or do we have to hack restfull_auth or authlogic to do that...

Did test server port change in Rails 2.3?

I upgraded rails to 2.3.2 from 2.1.1 yesterday and a bunch of my tests started failing. When I was running under 2.1.1, the test server was running on port 3000 so I had a HOST_DOMAIN variable that included the port - HOST_DOMAIN = "localhost.tst:3000". This is so my assert_redirected_to's would succeed. Now, however, it seems that th...

Rails after_save callback to create an associated model based on column_changed?

Hi, I have an ActiveRecord model with a status column. When the model is saved with a status change I need to write to a history file the change of status and who was responsible for the change. I was thinking an after_save callback would work great, but I can't use the status_changed? dynamic method to determine that the history writ...

What's the best way to create a static page in Rails?

I've created some resources in my Ruby on Rails application: localhost/admin/books localhost/admin/users localhost/admin/... Now I want to create a static page which just contains links to these resources and is accessible from localhost/admin I've tried to create the page in /public/admin/index.html and it works, but unfortunately I...

What open source Ruby OR Rails project would increase your appeal to a potential employer?

Now that I know how to find a Ruby open source project, how do I judge which ones are most likely to help my career prospects. I've never worked in the Ruby world and need something that might show off my potential to be a good hire. Or is any project as good as anything else as long it's something you're interested in? Also, would it ma...

How do others set up foreign key relationships in migrations

Hi, I'm developing some things in Ruby on Rails, and I've currently got several models with relationships between them. Now, the models specify the relations, so I know that RoR will enforce integrity, but what about at the DB level ? Do other people set up foreign key relationships in DB tables ? and if so, how ?, there doesn't seem ...

How to setup and work with RoR Complex Joins?

This code is taken from a previous question, but my question directly relates to it, so I've copied it here: class User < ActiveRecord::Base has_many :group_memberships has_many :groups, :through => :group_memberships end class GroupMembership < ActiveRecord::Base belongs_to :user belongs_to :role belongs_to :group end class...