ruby-on-rails

Ruby Rails Gems question...

I'm trying to install a Jabber Client called PSI on Linux Redmine installation. So, I have done the following: $ gem install xmpp4r $ cd {REDMINE_ROOT} $ git clone git://github.com/mszczytowski/redmine_messenger.git vendor/plugins/redmine_messenger $ vim config/messenger.yml #( <- Haven't set this up yet.) $ rake db:migrate_plugins...

Routing HTTP verbs in Rails

I'm trying to route only an http verb. Say I have a comments resource like so: map.resources :comments And would like to be able to destroy all comments by sending a DELETE /comments request. I.e. I want to be able to map just the http verb without the "action name" part of the route. Is this possible? Cheers ...

How to get fixtures data in describe scope

Hi. I'm struggling with spec for generic shared-exapmle here. But I can't get fixtures data in describe scope. Like below describe BlogController do fixtures :blogs { :show=>{:month=>blogs(:one).month, :day=>blogs(:one).day}, :edit=>{:month=>blogs(:one).month, :day=>blogs(:one).day} }.each |act, prams| do describe "blo...

Testing before_filter gets called in action

How would one test that when an action in controller is being accessed, that controller's before_filter will be executed? The before_filter is tested in separate example group so that there's no need to duplicate the tests for all actions that depend on the before_filter. If I have controller.should_receive(:my_before_filter) in my ...

Form not using default values from migration

So I have model with an association and I'm using a single form with "accepts_nested_attributes_for" to create records. In the form I have a few select drop downs for the child that aren't always required to have a selected value and when that situation happens I want to use the default value I've specified in my migration. So if I sub...

Is there any limitation on YAML indentation level?

I am developing a Ruby on Rails application with I18n support. I created a YAML file. But Rails report there is syntax error in the YAML file. I found that if I decrease the level of indentation for that error line, no error message come out again. Is there any limitation on YAML indentation level (in Ruby on Rails)? Here is YAML bloc...

Ruby on Rails: how to extract part of web-app?

I have a big application and I need to extract part of this application to separate small application. I'm going to develop big application, but I want to small app to be up to date. What should I use for this purpose? P.S. I use Ruby on Rails 3 ...

Authlogic: How to find if a user was not logged in because the user was not logged in.

I am using authlogic with rails application for authentication. The perishable token is reset after the user resets his password. Consider this case. A user signs up, he forgets to activate the account and he also forgets the passwords. So he resets the password. Due to this his activation link no longer remains valid. So he cannot activ...

Atom or RSS2 feed and a product image

Have a Ruby on rails site and want to use mailchimp's rss campaign. With it I need to send one image in the email. At the moment, I can only get the image to display if I add it to (description in RSS) or (entry in atom) along with the description of the product. How can I get it to display on its own "Channel". I tried this on the R...

Has many relationship in rails

Hi all, I have this relationship in a Rails app class Folder has_many :elements end class Element belongs_to :folder end My problem is this code doesn't work element = Element.first a_folder.elements << element element.save! a_folder.save! , but this one works: element.folder = a_folder element.save! Anyone can tell me why...

User defined form in Rails

I am creating a rails app wherein I have a problems model. How do i create a form that asks the user to choose the range of values that he wants to see. i.e the form asks him to choose say the cause of the problem and between what dates such problems could have occurred and then output those results from database? Thanks in advance. ...

rails searchlogic and will_paginate undefined method `order' for #<WillPaginate::Collection:0x37530ac>

Does anyone have the same problem or a working solution? I get always this error message, here are model, controller and view code class Profile < ActiveRecord::Base cattr_reader :per_page @@per_page = 10 end def index @search = Profile.search(params[:search]) @profiles = @search.paginate(:page => params[:page]) end <%=...

Problems posting headers using Ruby Net:HTTP module

I receive a POST with the necessary details from the credit card processing company on SiteA, SiteA determines if that post is for itself, if not it will again post the details to SiteB Here's the code on SiteA if request.post? ## this request obj contains the info posted by the cc company if params[:site_name].downcase != "...

double nested model

Hello, I have a model : todo which is nested to my organization and my project models. I don't know how to handle this case when I create a new todo because in my todo controller and in my view my code is linked to organization or to project. Is there a way to use the good one with a condition? Thanks in advance! ...

Nested resources without controller names in url

I've got a very simple Rails 3 app with a User model run by Devise and a Notes model. Right now the url and routing looks like this: # url /users/MEMBERNAME/notes/TITLE-OF-NOTE # routing resources :users do resources :notes end But I would like the urls to look like this, how would the routing look like in this case? # url /MEMBER...

Quick AJAX responses from Rails application

I have a need to send alerts to a web-based monitoring system written in RoR. The brute force solution is to frequently poll a lightweight controller with javascript. Naturally, the downside is that in order to get a tight response time on the alerts, I'd have to poll very frequently (every 5 seconds). One idea I had was to have the A...

Newbie to RegEx..

I have this sample string : &Lt;! [If Gte Mso 9]>&Lt;Xml> &Lt;Br /> &Lt;O:Office Document Settings> &Lt;Br /> &Lt;O:Allow Png/> &Lt;Br /> &Lt;/O:Off... And I would like to target specifically anything that begins in an "" and ends in a ">", and replace it with no-space "". Been using Rubular, but I'm having a tricky time learning ...

MySQL / Ruby on Rails - How to "SUM" in a :has_many case

Hi there, I have the following tables: User :has_many Purchases Item :has_many Purchases Item has a column "amount" (can be + or -) and I need to find all Users that have a positive SUM of "Item.amounts" (over all Purchases each one has made). How does this query look like? (I'm not sure how to handle "SUM" correctly, in this c...

Ruby's Truncate unsanitizes MS Word code..

Curious if anyone ever noticed this, but I have a WYSIWYG that users occassionally paste from word into. There is a word sanitizer, but not everyone's a genius. If I parse that text somewhere else, it comes out right. But if I truncate it, then the msword code appears. Does anyone know why truncate unsanitizes this || does anyone know ...

Expectation for find not working, but expectation for find_by_id is

I have this controller code: # GET /cardsets/1 def show @cardset = current_user.cardsets.find_by_id(params[:id]) end And this RSpec test code (mocking with Mocha): # GET Show context "on get to show" do it "should assign cardset" do @cardset = Factory(:cardset) @profile = @cardset.profile @profile.cardsets.expects(:f...