ruby-on-rails

rails namespace always pointing to one action

I have a rails application in which i have a namespace in the route as below map.namespace :admin do |admin| admin.resources :products end I have the controller under app/controller/admin products_controller.rb has various actions like index, show, edit, new, create, update, destroy wh...

rspec association test only works in one direction

I upgraded to Rails 3 and RSpec 2 and one of my RSpec tests stopped working: # Job.rb class Job < ActiveRecord::Base has_one :location belongs_to :company validates_associated :location end # Location.rb class Location < ActiveRecord::Base belongs_to :job end # job_spec.rb describe Job, "location" do it "should have a ...

Help with SQL query

Short database schema: users (id) games (current_player_id) // has many cards cards (author_id, game_id, content, created_at) game_views(game_id, user_id) //shows which games user have seen I need to find game for user, which meets all whose rules: game's current_player is NULL (the game do not played by anybody right now) author o...

How to group and count in rails

I am currently trying to create graph statistics for jobs in a PBS. I have a jobs model that has many fields, among them is a "Group" field. I would like to know how many jobs each group has executed. For that, I need the following query: SELECT jobs.`group`, COUNT(`group`) AS 'number_of_jobs' FROM jobs GROUP BY jobs.`group` Which re...

How to I resize images with the auto_html gem in ruby on rails?

Hi folks, I am using the auto_html gem to embedd images and videos in my rails app. But I 've got a small problem. Is there a way to resize the images to a predefined size? Thanks in advance lg tabaluga ...

rspec refactoring?

I have the following test, with two almost identical blocks. Now i am looking for ways to refactor this cleanly. The test: context "with the d1 configuration" do before (:each) do # send a message @envelope = Factory(:envelope, :destination => '32495xxxxxx', :message => 'Message sent by d1') @distributor = Distributor.fi...

Rails: How to name a attribute of a model in a specific way?

Hey Guys, i am searching for a solution of my little problem - maybe you wanna help ^^ I have in Ruby on Rails modeled to classes "Person" and "Contact". A Person can have many contacts and a Contact can have one specific person and describes this relation with a value class Person < ActiveRecord::Base has_many :contacts end class C...

Rails: Send put method from a index view

Hi everybody, I want do be able do update some values direct form the index view of my subscription Resource. To do so I try the following code: subscription_path(subscription, :method => :put) The problem is, that this goes directs to the show action as if the method would be :get! Thanks for your help! Maechi ...

How can I add my controllers and views in a plugin for rails

I am trying to make a test plugin . Although I am able to add methods to activerecord from my plugin , but I am not able to define a controller and view in my plugin . I thought , I would just inherit from ActionController::Base and then define a route and it would reach my plugin but that does not seems to work . Do I need to do anythi...

rvm conflit with sqlite3

Hi $: /Users/dev/.rvm/gems/ruby-1.9.2-head@rails3/gems/sqlite3-ruby-1.3.1/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] Abort trap It's seem that ruby is not the correct version (1.8.7) but : $: ruby - v $: ruby 1.9.2dev (2010-07-15 revision 28653) [x86_64-d...

How can I return javascript from a Ruby on Rails helper method?

I have a Note model, which can contain have either an image link attachment (linktype = "image" or some text (linktype = "text). When I display the notes, the method of display changes depending on the linktype. An example is: <% @notes.each do |q| %> <h2 class="title"><%= q.name %></h2> <% if q.linktype == "other"%> <sc...

Testing rails controller with rspec within a plugin

I'm writing a Rails plugin and I'd like to be able to test a controller within the plugin: describe ReportsController, :type => :controller do it "shows paginated reports if the user is authorized" do get 'index' response.should render_template("index") end end unfortunately this results in the following error: NoMethod...

LocalJumpError ( No Block Given ) in Rails

I'm running this method, and this works perfectly on my local machine but does not work on my remote server. I get that it's looking for a block, but I'm not sure 'where' or 'how' to place it. Here's my broken method: def generate_csv if params[:print_envelopes] @signups = CardBatch.find(params[:id]).card_signups.each.reject { |a...

Searching multiple columns with Sphinx

Hi! I have model Products with columns: name, number, description Index defined for this model looks like this: define_index do indexes :name, :sortable => true indexes :number indexes :description where "amount > 0" has :price end Since in description can be lots of random words I want to exclude it from searching somet...

Controller Spec with and without lambda + "should change"

I am testing a simple password reset action and would like RSpec's "change" matcher for lambdas. But it doesn't work for this controller action. Everything works fine without that matcher. Here is the spec: describe "#update" do it "Updates the password and resets the token" do @user = Factory :user getter = lambda{ get :edit,...

Rails: base64 and character escaping problem

In my app I need to encode a string via base64, escape it's possible special characters and put it into a URL. I do the following: string = "[email protected]" enc = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC') enc.encrypt('dummy_salt') encoded = URI.escape(Base64.encode64(enc.update(string) << enc.final)) The problem is, that ...

How to persist data about what page you are on in Rails app

This will probably be easiest if I explain what I'm trying to do. I have three actions in my Rails app controller, each rendering a different page. The page-render is done with a single partial which uses variables that were set in the controller action code. For example, each page has a list on it, but on one page the list is sortabl...

creating records in .each in lambda{} doesn't change a number of records in RSpec

I initially wrote testing code like the following; fixtures :records it "should double number of records " do @payment_transactions = PaymentTransaction.find :all length = @payment_transactions.length lambda{ @payment_transactions.each{ |pt| PaymentTransaction.create(:data => pt.data) } }.should change{PaymentTr...

Good way to assign protected attributes

Easy part: I have model with protected attribute and I have action which can be accessed only by admin, how to force assigning all attributes, so I don't need to do something like this: @post = Post.find(params[:id]) if params[:post].is_a?(Hash) && params[:post][:published] @post.published = params[:post].delete(:published) # delete ...

Facebox and rails not working!

Am trying to use Facebox with rails, it's not working at all. I have added all files to there right places: Install FaceboxRender gem install FaceboxRender Download jQuery Download facebox at http://famspam.com/facebox Copy facebox js file to /public/javascripts/ Copy facebox css file to /public/styleshees/ Copy facebox all image file...