ruby-on-rails3

Putting the API under its own domain

I think there is a wide consent that is a good practice to separate your REST API from your main website. The main reason is that you can scale your API and website independently of each other. Additionally, Rails has a lot of middleware that is not required for stateless services (e.g. sessions, cookies, view rendering, etc...). Jeff D...

How to get Capybara to see Javascript in plugin directory when creating plugins?

We're developing a plugin for rails, and I've got Cucumber working with Capybara wonderfully. BUT, when developing, I've been (erroneously, I guess) putting the Javascript files in the parent test application's public/javascript directory. So when Capybara runs, it doesn't find the javascript file. How can we get Cucumber/Capybara to see...

I was trying to install sqlite3 interface for ruby in my mac snow leopard 10.6.3. But i got the following error any suggestions ?

for this command i got this error "sudo gem install sqlite3-ruby" Building native extensions. This could take a while... ERROR: Error installing sqlite3-ruby: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb mkmf.rb can't find header files for ruby at /Syste...

Does this Rails 3 Controller method make me look fat?

This is a new application, and I have an index method on a Search controller. This also serves as the home page for the application, and I'm trying to decide if I am headed down the wrong path from a design pattern perspective. The method is already 35 lines long. Here is what the method does: 3 lines of setting variables to determine...

Rails 3 Routing Error

I had this working yesterday, I don't know what I did to break it. Here are the routes for a RESTful controller: brand_responsibilities GET /brands/:brand_id/responsibilities(.:format) {:action=>"index", :controller=>"responsibilities"} brand_responsibilities POST /brands/:brand_id/responsibilities(.:format) ...

Can you use RSpec, Shoulda, RCov?

I am attempting to get RCov to work with my RSpec and Shoulda test for a rails 3 app. It seems to work fine with my RSpec after using the Rake task below but all of the shoulda tests fail and I cant seem to find any documentation on getting these to work. They all run fine under autotest(rspec and shoulda). namespace :spec do desc "...

Error using ActiveResource with Rails 3 and REST API

I have a REST API that I am trying to access using Rails 3.0.1 that returns: <Sessions> <Session> <Title>This is a sample title</Title> ...Misc </Session> <Session> <Title>Another Title</Title> ...Misc </Session> </Sessions> I have set up my session.rb class defined: class Session < ActiveResource::Base self...

Reversing a hash

I had taken from the database and sorted it according to the position. Then I had put the necessary datas into a Hash. After putting the data in hash and I printed the hash. But the result is in reverse order. So I want to reverse the hash. How can I do this? ...

Help with rails active record querying (like clause)

I want my code to do two things that is currently not doing @students = Student.where(["first_name = ? OR middle_name = ? OR last_name = ?", params[:query].split]) Work. (it says im supposed to pass 4 parameters but I want the user to be able to type words and find by those words on each of those fields and return whatever matches) A...

ActiveRecord3 deadlock retry

Are there any plugins for Rails 3 (or ActiveRecord 3) that replicate the old deadlock_retry plugin? Or, does that plugin still work with Rails 3? ...

Add constraint to route to exclude certain keyword

I am using Rails and I want to use contraint in route to exclude that route if keyword "incident" is anywhere in the url. I am using rails3. Here is my existing routes. match ':arg', :to => "devices#show", :constraints => {:arg => /???/} I need to put something in constraints so that it does not match if word "incident" is there. ...

Custom Inflections not working on rails3?

I'm using Rails (3.0.1) and have the following code in initializers/inflections.rb ActiveSupport::Inflector.inflections do |inflect| inflect.irregular('nursery', 'nurseries') end From the console I'm getting: "nursery".pluralize => "nurseries" "nurseries".singularize => "nurseries" I should be getting: "nurseries".singularize => ...

Rails 3 - Creating a JSON response to display Search Results

Hello, I'm working to have Rails 3 respond with a JSON request which will then let the app output the search results with the jQuery template plugin... For the plugin to work, it needs this type of structure: [ { title: "The Red Violin", url: "/adadad/123/ads", desc: "blah yada" }, { title: "Eyes Wide Shut", url: "/adadad/123/ads", d...

Issues with using subdomains with Cucumber/Capybara

I have successfully added the ability to use dynamic subdomains within my application. The issue is that when I run my Cucumber tests, I receive the following error when my application performs a redirect_to which contains a subdomain: features/step_definitions/web_steps.rb:27 the scheme http does not accept registry part: test_url.exam...

How to mock request object for rspec helper tests?

I've a view helper method which generates a url by looking at request.domain and request.port_string. module ApplicationHelper def root_with_subdomain(subdomain) subdomain += "." unless subdomain.empty? [subdomain, request.domain, request.port_string].join end end I would like to...

How do I implement basic authentication with sessions in Rails?

Just learning Rails via Michael Hartl's tutorial and one of the things we have to do is implement basic authentication with sessions instead of cookies. I am trying to find any literature online that discusses it, but can't find anything. The Rails Guides talk about sessions from a security point of view, so they assume you have your a...

Rails 3 - Truncate in a Controller?

Hello, in my controller I'm building a json object for books. I want to show truncate(book.content, 250) but that doesn't work in a rails controller? And given it's a JSON render, I don't use a view. So how does one truncate? I don't want my JSON object to be huge :)! thanks ...

Error running autotest on Windows 7 with Rails 3, Ruby 1.9.2

Installing and running Rails 3 and Ruby 1.9.2 on Windows 7 went rather smooth. It's only now that I want to run autotest that I'm running into problems. The error looks frustratingly simple, but I can't figure out how to solve it. I have the following gems in my Gemfile: gem 'autotest' gem 'autotest-rails-pure' But then when I run ...

Changes to the code are not getting reflected in Rails 3.0

Hi, I have started a project using Rails 3.0. I am using devise for the authentication. Devise includes links to signin and forgot password in the sign up page. These links are loaded by means of a partial.I did not need these links, so I removed them and reloaded the page, but still these links remain. I tried clearing the cache and ...

uninitialized constant Ckeditor::PLUGIN_CONTROLLER_PATH

I've try to use ckeditor in my apps. I followed instruction how to install it, but when I came to this step $ rails generate ckeditor:base I got this error message, uninitialized constant Ckeditor::PLUGIN_CONTROLLER_PATH, and I didn't know to solve it. Does any body know how to solve it? please. ...