ruby-on-rails

How to make JQuery UI work in a partial?

I am a COMPLETE beginner at JQuery (and javascript in general) but I'm having a go at this. Simple setup: Layout contains view, which contains simple JQuery tabs just like http://jqueryui.com/demos/tabs/default.html. I have the following haml in layout head: %head = javascript_include_tag "jquery", "ui/jquery.ui.core", "ui/jquery.ui...

RoR: Why is this if-statement failing?

Why is the second if statement failing in the following code block? The output from the console indicates that the private parameter is 0, so it should be passing? The private parameter is from a checkbox in the new form, that I'm using to set a boolean field in the model. if (((params[:note])[:text]) != "") logger.debug("passed first...

Renaming Ruby on Rails application

Is there a way to rename the application in Rails 2? ...

Heroku / "fatal: pathspec '.gems' did not match any files"

Hi, I am trying to deploy one ROR app on Heroku. As I typed "git push heroku master", I got this : -----> Heroku receiving push -----> Rails app detected -----> WARNING: Detected Rails is not declared in either .gems or Gemfile Scheduling the install of Rails 2.3.8. See http://docs.heroku.com/gems for details o...

Is it a bug for method hash#to_json in Rails?

I use rails 2.3.8 def index @posts = Post.all respond_to do |format| format.html # index.html.erb format.json { render :json => ({ :results => @posts.size, :rows => @posts.to_json(:only => [:id, :title, :click_count, :body])}).to_json } end end the generated json data is: {"rows":"[{\"title\":\"ruby\",...

Why am I getting a "SystemStackError: stack level too deep" in my rails3 beta4 model

Hi there. I'm getting the following error: SystemStackError: stack level too deep when executing the following code in rails3 beta4 under ruby 1.9.2-rc1: ruby-1.9.2-rc1 > f = Forum.all.first => #<Forum id: 1, title: "Forum 1", description: "Description 1", content: "Content 1", parent_id: nil, user_id: 1, forum_type: "forum", create...

Ruby on Rails Mongrel error

When I click on the "about your application's environment" button on the "welcome" your riding rails page this happens in my server console. ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... ** Rails loaded. ** Loading any Rails specific GemPlugins ** Signals ready. INT => stop (no restart)...

Is there any partial kind of thing for controllers in Ruby on Rails

I have a controller having more than 1000 lines of code. Right not I am doing Code review for this controller. I arrange my methods according to the module. Now I realise that my controller is not easy to maintain and so I want to something like following class UsersController < ApplicationController #Code to require files here ...

RoR select, retain item value

hi i am listing items using "select" on selecting an item-3 from the list iam reloading the page, same for all the items. When page reloads, select takes to item-1 again. I want to retain item-3 even after page reload. ...

rails - authentication, authorization and auditing confussion

Hey, I am trying to decide on an AAA plugin/s but there seems to be so many of them! and alot of the posts seem quite old, 07/08. I saw goldberg but it seems like the site is down... my app needs login,logout and forgotten passwords and needs to be able to restrict a user based on controllers/methods(role based). On the auditing si...

Compiled Application with Ruby config files (yml)

I compiled a program from source on mac os x which tells me to use the supplied example config files, but how can I run a specific config file? Readme shows what to edit in the config but not how to load it. More specifically this program (http://github.com/carsonmcdonald/HTTP-Live-Video-Stream-Segmenter-and-Distributor) ...

Set path of views and controller for my PLUGIN

How i change the path of views folder to myplugin folder when i make new plugin. Every time i call an action whose controller is in myplugin's folder. Please help me each time it call the view of my app and not vendor/plugin/myplugin/views folder Please help me Thanks in Advance ...

validates_format_of to exclude certain patterns

I want a rails model to exclude certain patterns: runs of two or more spaces. User.name = "Harry Junior Potter" is valid, but User.name = "Harry Junior Potter" is not (two spaces between Harry and Junior). This to avoid identity theft, where those two names are displayed the same (HTML compresses runs of whitespace). In other words:...

Multiple counter_cache in Rails model

Hi. I'm learning Rails, and got into a little problem. I'm writing dead simple app with lists of tasks, so models look something like that: class List < ActiveRecord::Base has_many :tasks has_many :undone_tasks, :class_name => 'Task', :foreign_key => 'task_id', :conditions => 'done...

ActiveRecord and has_many, :through link backs

Is there a simple way to specify a has_many :through relationship where you're linking the same data type? eg. One User has many friends (who are all users). I'd like to be able to store data about the friendship, so has_many :through seems to be the obvious choice, but then you'd have to define two :user_id columns, which of course does...

What's the best way to detect date formats in user submitted data?

I'm reading csv data uploaded by users in my Ruby on Rails app. When a user specifies that a particular column has dates(or times), I want to be able to automatically detect the format. This means it can be in American or British formats (any of dd/mm/yy, mm/dd/yy, yyyy-mm-dd, 12 Feb 2010, etc etc) I have tried parsedate in Ruby but i...

How to sort the embedded objects in MongoDB

Suppose I have some objects in MongoDB: { "_id":xxx, "name":"mike", "children": [ {"name":"A", "age":3}, {"name":"B", "age": 5} ] } If I want to get this "mike" with his children sorted by "age desc", what should I do? I've looked at Mongoid(in rails), and morphia(in Java), not found th...

Rails - update_attributes coming up against validations

So I've got a user model, with login, email address, password, password confirmation, name, avatar (picture), etc. There are validations on the first 5, basically stating that all 5 need to exist in order to create a new model. However, this causes problems for me where updates are concerned. I've got an edit page, where the user can o...

Sort Array in Controller

Hello I'd like to sort an array in a Rails Controller. I want to sort the array before I loop over it in the View @projects = Project.all.sort #throws error #and @projects = Project.all @projects.sort # throws error throws this error: undefined method <=> for #<Project:0x101f70b28> but when I query: @projects.respond_to...

Inconsistent HTTP Errors from Uploading Images with Uploadify and Ruby on Rails

I'm having great difficulty in finding a bug preventing some uploads to my rails app through Uploadify. Here is the error I'm receiving: http://j.imagehost.org/0353/uploadify-errors.png The thing that's making this difficult is that it's not at all consistent. Sometimes the images will upload perfectly fine. Other times they won't. Th...