ruby-on-rails

Add a value to a delete link in Rails?

I currently have the following link_to in my Rails application: <%= link_to 'Remove this Person', @person, :confirm => 'Are you sure?', :method => :delete, :class => 'important', :class => "minimal important" %> I would like to add the person's name in place of the "this person" for the link. I don't appear to be able to do: <%= lin...

Tell the end of a .each loop in ruby

If i have a loop such as users.each do |u| #some code end Where users is a hash of multiple users. What's the easiest conditional logic to see if you are on the last user in the users hash and only want to execute specific code for that last user so something like users.each do |u| #code for everyone #conditional code for las...

How can I create a time-series array so I can have a bar graph in Ruby on Rails?

I have a model, ContactEmail that has a date_sent attribute and an email_id, referencing another model Email. I would like to create a bar graph which shows on the x-axis dates and on the y-axis the number of ContactEmails that were sent on a specific date. I would like to also do the same, filtered for ContactEmails where email_id equ...

Rais 3 - Setting up PhotoAlbum & Photos

Hello, I've created: PhotoAlbum (id, name) has_many: photos Photo (id, name, photo_album_id) belongs_to: photo_album I want to allow a user to upload 1 or more photos. Per Upload whether it be 1 or more photos, they should automatically be added to a new album. So the way i have it is, a user clicks upload photos: They get the ...

How can I create an array of ints in Rails 3. Please help!

Hello! I have a very small question. How can I convert these: [172592596,93038592,154137572] To look like these: ['172592596','93038592','154137572'] Thankful for all help! ...

How to render a partial in a plugin from a plugin helper

I have a helper in my plugin test_plugin/lib/test_helper.rb: module TestHelper def test_render render 'test_plugin/test_partial' end end I have a partial test_plugin/app/views/test_plugin/_test_partial.html.erb: <p>Hello World!</p> In my application app/views/tests/index.html.erb when I do this: <%= test_render %> I get ...

Rails/Devise - Add ruby code in a locale file ?

Hi, I would like to know if there is a way to add ruby code in a locale file. For example: devise: failure: unconfirmed: 'You have to confirm your account before continuing. <%= link to "send confirmation instructions?", user_confirmation_path %>' Thanks for your help! ...

Changing error display format in Rails ActionView Helpers

I'm trying to modify the default behaviour of showing errors before the form to show them next to the fields instead. I'm using this to achieve that: ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if instance.error_message.kind_of?(Array) %(#{html_tag}<span class="validation-error">&nbsp; ...

What is my document onLoad hander in Rails?

I want to use a plugin to make most of my models inline editable, but I don't understand the following: To use it, include jquery.rest_in_place.js in your template and execute the following in your document’s onLoad handler: jQuery(".rest_in_place").rest_in_place(); http://jan.varwig.org/projects/rest-in-place Where do ...

Rails 3 single table inheritence w/ has_many question

I've been trying to setup a Single Table Inheritance model in Rails 3 in which the parent class also contains a has_many relationship. Unfortunately I can't get it to work. Here are three classes as an example: class Article < ActiveRecord::Base has_many :paragraphs, :dependent => :destroy, :autosave => true end class Paragraph <...

How can I add a red error message for wrong input in the form in rail3?

So in rails, if any of the input is not valid, the page returns back to the input page and red errors will show up next to that input_text or textarea. For example, <% validates_presence_of :email %> It will say the error at the top, and the email input text turns into red. However, when I separately made a valid checking statement...

How do I test the title of a page from an RSpec view spec?

I'm learning RSpec 2 with Rails 3. In order to set the contents of the tag in the layout for each page, I have a helper that can be used to set the title and then return it: def page_title(subtitle=nil) if @title.nil? @title = ["Site Name"] end unless subtitle.nil? @title << subtitle end @title.reverse.join " - " en...

Is it possible to add devise, if user model already exists?

We already created a user model in the beggining of the project, but now (several migrations later) we would like to use the devise gem. Is it possible to add devise if the user model and table already exist? That is, is it possible to alter what is already done, or do we have to start all over again? ...

Rails - Paper_Clip - Support for Multi File Uploads

Hello, I have paper_clip installed on my Rails 3 app, and can upload a file - wow that was fun and easy! Challenge now is, allowing a user to upload multiple objects. Whether it be clicking select fileS and being able to select more than one. Or clicking a more button and getting another file upload button. I can't find any tutorials ...

Calling alias_method from an ActionController, NoMethodError

In Rails 3 I'm trying to call alias_method from my before_filter but I'm getting this error: NoMethodError in MyController#index class ApplicationController < ActionController::Base before_filter :my_test protect_from_forgery helper :all def my_test debugger alias_method :new_method_name, :old_method_name end en...

Rails - jquery-html5-upload ?

Hello, Has anyone been able to get the jquery-html5-upload plugin to work with Rails 3 + PaperClip + S3? Know of any tutorials? http://code.google.com/p/jquery-html5-upload/ Thanks ...

WEBrick alterative for Rails 2.3.8?

I'm a Rails newbie, and I was initially using NetBeans + JRuby to make Rails apps (was using JRuby because it was a quick start - I don't need to interface with any Java libs). Then because of (a) many gems are not available for JRuby, and (b) most of the Rails webshosts don't support JRuby, I decided to use Ruby MRI. So I got everythi...

With Rails, how to convert code which used Facebooker to using Facebooker2?

There is code to use Facebooker gem (which uses the old Facebook REST API). Does someone have experience how to convert those code to using Facebooker2, which uses the new Facebook Graph API? For example, Facebooker has Facebooker::Session and Facebooker::User and they are both gone in Facebooker2. I can't find too much docs on the tw...

Augmenting Bates' `find_commentable` method

I'm watching a Ryan Bates screencast on polymorphic relationships, and he uses this private method for finding all comments related to a nested model. So I could find all the comments of a given Post with this : def find_commentable params.each do |name, value| if name =~ /(.+)_id$/ return $1.classify.constantize.find(value...

What does "Anonymous modules have no name to be referenced by" really mean?

I'm upgrading my Rails app to work with Ruby 1.9 and I keep encountering errors like this: Anonymous modules have no name to be referenced by /home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:585:in `to_constant_name' /home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.r...