ruby-on-rails

Getting the first of a GROUP BY clause in SQL

I'm trying to implement single-column regionalization for a Rails application and I'm running into some major headaches with a complex SQL need. For this system, a region can be represented by a country code (e.g. us) a continent code that is uppercase (e.g. NA) or it can be NULL indicating the "default" information. I need to group thes...

How to submit multipart messages using ActiveResource?

I am trying send user profile images from a client to the server using ActiveResource. It looks like ActiveResource doesn't support multi-part. Is there a gem/plugin that adds Multipart support to ActiveResource? Or any other alternative approach to addressing this issue. ...

Why is my html getting mal-formed?

I have the following table in a form that's embedded in a formtastic form (semantic_form_for). Everything I ask to be generated by ruby shows up, but the table gets badly mangled (essentially, the tags NEVER get formed. The table headers get drawn correctly There are 14 available_date objects that get passed, and they alternate betwe...

Wrong root on image_tag, include_tags, etc

On my dev setup, generated routes are mysteriously pointing to my public www server. <%= javascript_include_tag :defaults %> [yields] <script src="http://www.mysite.com//javascripts/prototype.js?1265304231" type="text/javascript"></script> <script src="http://www.mysite.com//javascripts/effects.js?1265304231" type="text/javascript"><...

Can i return a value instead of a view from my controller?

I would like to return the id of a newly created object for my ajax call instead of returning the view associated with the controller method. ...

i want to add my gallery to facebook from the localhost

I am working on photo sharing web site and i want to add functionality which can create my application's whole gallery in to the face book gallaries . Is ther any code whch can be added to do such things . Please help me out . IF find any link, kindly share in the answer , i hope i am clear anough ? ...

autologin in authlogic Rails

Hello, I have added auhlogic in my Rails app to authenticate users. I have also included the code from the Reset password tutorial . All of it works, the only issue I have is that once a user registers he gets automatically logged in. Anyone worked with authlogic, what would be the best & fastest way to disable the autologin after the...

GEM Version Requirements Deprecated

When creating a new Rails project using: rails sample Then creating a model using: script/generate model person first_name:string last_name:string Everything is fine. However, if I add any gems to my environment.rb: config.gem "authlogic" And run the same generator, I get the following: /Library/Ruby/Gems/1.8/gems/rails-2.3....

Ruby on Rails Drawbacks

Ruby on Rails is maybe the most praised web development framework exist. There are tons of reasons for that, but every framework, even the best of its kind, has its drawbacks. I'd like to know the most common problems you run into when developing Ruby on Rails applications and the issues you often struggle with. ...

validates_associated in production

Hi all. Imagine a simple model. class Service belongs_to :user validates_associated :user accepts_nested_attributes_for :user end Nothing special right? The validations on the associated User model trigger correctly in development mode. But don't do anything in production. I've added a validates_on_presence :user just like the d...

Mock Terminal Console/Live Command Updates in Ruby on Rails

In my app, a user can run a script, and if it is run in the terminal, it shows a nice progress bar, how would I replicate this in rails? I mean I could do like something between the two to communicate, but I would prefer if it would just show a "live" shell output. Thanks :) ...

How do I debug a Net::HTTPInternalServerError error when using Mechanize?

c:/ruby/lib/ruby/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:259:in `get': 500 => Net::HTTPInternalServerError (Mechanize::ResponseCodeError) I get the above error when I try to navigate to the following webpage http://fakewebsite.com//admin/edit_building.cfm?page=buildings&amp;updateMode=yes&amp;id=1251 I can navigate just fine ...

OAuth in Rails - google, twitter, facebook, connect for login like stackoverflow login

Rails has the rest autho plugin which works well but is there a solution for incorporating twitter, facebook, google, yahoo, etc... Seems like each on has its own plugin and demands and mixing them is going to be a mess. This is for logging in users like how Stackoverflow gets things done not for using the robust features of the APIs. ...

How do I print out the cookies that Mechanized has stored?

I'm using mechanize to login into a website and then retrieve a page. I'm running into some problems and I suspect this is due to some values in the cookies. When Mechanize logs into a website I assume it stores the cookies. How do I print out all the data stored in the cookies by Mechanize? ...

How to set default date in date_select helper in Rails

I'm trying to set up a date of birth helper in my Rails app (2.3.5). At present it is like so. <%= f.date_select :date_of_birth, :start_year => Time.now.year - 110, :end_year => Time.now.year %> This generates a perfectly functional set of date fields that work just fine but.... They default to today's date which is not ideal for a d...

Rails and image gallery: how to make it flexible?

Hy! In my app, every profile has a gallery and this gallery has images. They can have 1 or 1000 images, so when i show up the gallery i only need a part of the images, let's say 12 images. Then in my ajax gallery when, someone requests more images are loaded. This gallery is SEO, so, the main url is: "/profile-url/" and then, there are...

caching static files for ruby on rails application using nginx

I have been trying for some time to serve & cache static files for my rails app using nginx. the rails app server runs mongrel_cluster and is deployed on a different host than that of nginx. following many of the available discussions I tried the following server { listen 80; server_name www.myappserver.com; ...

Type attribute for text_field

I have this code: <%= f.text_field :email, :type => "email", :placeholder => "[email protected]" %> So people can enter their email on an iPhone with the email keyboard instead of the ASCII keyboard. However, the output is: <input id="user_email" name="user[email]" placeholder="[email protected]" size="30" type="text" /> which should...

how can I generate json from respond_to method in rails?

If I have a block of code like this: def show @post = Post.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @post } end end How do I add something like format.json Any tips, pointers, ideas gladly welcomed... ...

work with rescue in Rails

Hi, I am working with the following piece; def index @user = User.find(params[:id]) rescue flash[:notice] = "ERROR" redirect_to(:action => 'index') else flash[:notice] = "OK" redirect_to(:action => 'index') end Now I either case whether I have a correct ID or not, I am always getting "OK" in my view, what am I...