ruby-on-rails

Rails Ajax Hide/Show Toggle Link using RJS

Hello, I want users to be able to comment on submissions. Below each submission I want there to be a link that says "Comments (2)"...when you click on this link it dynamically loads in the comments, as well as a simple form to add a new comment. When the user submits a new comment I want it to load asynchronously in at the bottom of the...

How should I arrange my models and cron rake task to send emails on intervals with different start dates?

I'm re-evaluating my model and way I am trying to solve a particular problem. I have Contacts that can belong to a Campaign, which is a series of activities such as phone calls and emails, each with a number of days assigned as an attribute determining when it should get sent. I want the cron job to look and see emails which are due to...

Getting PG Error hard to debug when using delayed_job on heroku

I am trying to use heroku and appear to be getting a Postgres error but don't have enough information to know what to fix. The error is below, and it looks like it is trying to run delayed_job: > PGError: ERROR: value too long for > type character varying(255) : UPDATE > "delayed_jobs" SET "updated_at" = > '2010-09-12 01:06:59.354515'...

Tips for using Notepad++ for rails development?

I just started using notepad++ for rails development. Are there any plugins/options/tips that makes it easier to use for rails? Edit I ditched Notepad++ for Vim and it's been great. ...

InvalidAuthenticityToken from rails for POST request from openlaszlo app.

InvalidAuthenticityToken from rails for POST request Hi All I have a rails server running to which I make a POST request. The dataset is defined as Now per rails documentation in order to make a POST a request I need to set the add "authenticity_token" to the query string. So if for example the authenticity_token is "xxxxxxx", the fin...

What is the difference between starting a server binding to 0.0.0.0 vs 127.0.0.1?

It seems that Rails and Django can both start up the server binding to an IP, either 0.0.0.0, 127.0.0.1, or 192.168.1.2 <-- the last one is my local IP are there other choices? It seems that 0.0.0.0 and 192.168.1.2 can let a Virtual PC on the same machine access this website, while 127.0.0.1 cannot. However, if it is just the same ...

Shoulda helpers don't work

I have one spec: require 'spec_helper' # hmm... I need to include it here because if I include it inside describe block `method_missing` exception raises. include Shoulda::ActionController::Matchers describe CategoriesController do include Devise::TestHelpers render_views context "new should render template :new" do setup ...

Rails 3 UJS and XHTML

I have a simple question about how Rails 3 works with XHTML doctypes. Since Rails 3 uses UJS for its ajax calls (and even normal calls such as delete calls) and does so by use of HTML5 data attributes, then, since XHTML doesn't support data attributes, will the markup be automatically invalid? ...

Ruby on Rails: how do I catch ActiveRecord::Rollback?

In my controller, I have code that looks like the following: @mymodel.transaction do for a in arr @mymodel.some_method(a) end end in @mymodel#some_method I could throw an ActiveRecord::Rollback exception which in the db does what it needs to do, however I then simply get an HTTP 500 and no way to catch the...

Creating a Scope that joins user_id with the User Table (user.id) --- Rails 3

Hello, I'm using Rails 3 with devise. I have a table books which has a column for user_id, which is related to the Users table (user.rb) I'm trying to create a Scope that shows all the books with the user's email address (Books joined to Users) class Note < ActiveRecord::Base scope :personal, proc {|user| where(:user_id => user.id) }...

rpsec rails mocking session hash

I am trying to mock out the session hash for a controller like so: it "finds using the session[:company_id]" do session.should_receive(:[]).with(:company_id).and_return 100 Company.should_receive(:find).with(100) get 'show' end When I call get 'show' it states: received :[] with unexpected arguments expected: (:company_id) ...

Rails form_for model in different controller

I have the following model classes: class Upload < ActiveRecord::Base ... has_many :reviews, :order => "created_at DESC" ... end class Review < ActiveRecord::Base ... belongs_to :upload belongs_to :user validates_presence_of :description ... end My upload/show view has a form for to capture a review for the speci...

remove an embedded document in mongoid

Hello I have a projects model with just a name field and in it also the embedded relation to line_items. class Project include mongoid::document field :name embeds_many :line_items end class LineItem include mongoid::document field :title embedded_in :project, :inverse_of => :line_items en...

Catch all exceptions in a rails controller

Hi Is there a way to catch all uncatched exceptions in a rails controller, like this: def delete schedule_id = params[:scheduleId] begin Schedules.delete(schedule_id) rescue ActiveRecord::RecordNotFound render :json => "record not found" rescue ActiveRecord::CatchAll #Only comes in here if nothing else catches the e...

Rails 3 default datetime format without UTC

Hi all, I'm creating a new Rails 3 app, and in it I use datetime for a couple of fields, however every datetime field standard has UTC behind it (in a view), like: 2010-10-10 16:19:00 UTC How do I get rid of the UTC part? UPDATE: here's what I have so far: <%= trip.truckleft.strftime("%Y-%m-%d %H:%M") %> So all I have to do now...

Ruby on Rails. A custom message in a custom validator method

Hi. I want to have an ability to set a custom message in a model validator method to notify a user about incorrect input data. Firstly, I set a custom validator class where I redefine the validate_each method in that way as it recommended in rails' documentation: # app/models/user.rb # a custom validator class class IsNotReservedVa...

Should a class/module in lib be required ?

Hi, I just wrote a small module in my Rail 3.0.0 application lib folder: module AdminFilters def verify_is_admin if current_user.nil? || current_user.role != User::Role::ADMIN redirect_to :root, :alert => "You don't have enough permissions" end end end And in order to make it available for all my controllers : c...

What is causing this NoMethodError in Ruby on Rails?

This is the code I have at the end a the create method in Notes controller def create @note = Note.new(params[:note]) @note.user_id = current_user.id respond_to do |format| if @note.save flash[:success] = 'Note was created.' # @note.note_type is "Temp" at this point if @note.note_type == "Te...

Rails ActiveRecord: HABTM find parameters

I have 2 models: notes and tags. class Note < ActiveRecord::Base has_and_belongs_to_many :tags end class Tag < ActiveRecord::Base has_and_belongs_to_many :notes end A tag has a name (eg. "rss", "javascript" etc.). What is the best way to retrieve all notes that have a certain list of tags? That is, I would like to have a named ro...

Problem installing LESS for Ruby on Rails - script/plugin: command not found

I am trying to install LESS in a Ruby on Rails project. I am able to run the gem successfully, but when I try to install the plugin for LESS, I get an error. Here's what shows in the terminal: MacBook:benji jesse$ sudo gem install less Successfully installed less-1.2.21 1 gem installed Installing ri documentation for less-1.2.21... Inst...