ruby-on-rails

Rails - deleting a single record in a intersection table habtm

hey, I have a habtm relationship (assignments < assignments_candidates > candidates) I want to be able to delete one candidate off an assignment. here is my code so far @assignment = Assignment.find(:first, :joins => :candidates, :select => "assignments_candidates.*", :conditions => ["assignments_candidates.candidate_id = ? AN...

Render_template error Integration test in Ror

hi, I just trying the integration test in ruby on rails.. I have added a file layout_links_spec.rb require 'spec_helper' describe "LayoutLinks" do it "shuld hve a homepage" do get '/' response.should render_template("pages/home") end it "shuld hve a contactpage" do get '/contact' response.should render...

link_to_remote wants to render a template - how not to? rails

I want to delete my task ajax-style if some conditions are met. I do that with the help of link_to_remote. The thing is that link_to_remote wants to render a template and i dont want it to. In my view ( _task_sth.html.erb): <%= link_to_remote "Delete task", :url => {:controller => 'tasks', :action => 'delete_task', :task_pers_id => sor...

How to select only one element of associated objects in to_json / to_xml

I have the following problem. My App (a prototype of an api) should be able to react on params (like language). I'm already able to respond to an request by sending an entierly object (with associated objects included) as JSON. But now i want to select the associated objects by parameter. my code: object.to_json(include => { :texts_...

Rails form params issue

I'm constructing some data to send over jQuery's $.post, the data that I send looks like this: authenticity_token: LxHlgi1WU8o0DtaNuiQOit/e+HlGR2plVcToHUAhA6I= crews[0][boat_id]: 2 crews[0][crew][]: 10 end_time: 1280408400 start_time: 1280404800 Which is from jQuery converting the data object which is prepared by: creating an array ...

Testing two different expectations with mocking

I've recently just added Devise to my first Rails3 app, and I'm having a bit of trouble with the controller tests. I'm testing the User controller class, which is the same model that Devise uses. So at the beginning of my spec I have this: before(:each) do sign_in @user = Factory.create(:user) end Now I can get the test passing wit...

How can I produce some simple json with this Ruby class?

Here's a simple ActiveResource class. It has some instance variables and maybe even some methods, but it's not backed by any data. ruby-1.8.7-p299 > class Box < ActiveResource::Base; attr_accessor :a, :b, :c, :d; end => nil Let's populate it: ruby-1.8.7-p299 > bx = Box.new; bx.a = 100; bx.b = 20...

rails: create a single table without id

I've just generated my first scaffold in rails. Now, I don't want my table to have a field named "id". Instead I want it to be named "uid" which will be an arbitrary string. But I can't seem to get my head around how this is to be done. Especially with managing routes. I've managed to set :id=>false and define "uid" as the primary key bu...

Thinking Sphinx recipe for Supervisord?

Wondering if anybody has configuration to keep Thinking Sphinx running using supervisord ...

CKeditor forcePasteAsPlainText not working in 3.2..

I've heard mixed responses about this working/not working . Mine happens to not work since I've upgraded. I upgraded rails by using a rails plugin that install rails 3.2. http://github.com/galetahub/rails-ckeditor For non-rails users, this basically just installs the latest version of CKeditor with an external yaml file for handling...

In Ruby on Rails how can I persist objects in memory between sessions

I'm trying to build something (ultimately a gem but for now an application) that works as follows. Suppose for example the DB records are breeds of dog. There's a Dog parent class and a child class for each breed. The actual breeds aren't known until runtime. When the server begins it will load up records from the DB and instantiate ...

Difference between string and text in rails?

Hi I'm making a new web app using Rails and was wondering what's the difference between string and text? And when should each be used? Thanks ...

paperclip and functional test problems (rails)

I'm having problems with my functional tests involving paperclip and attachments. I'm using the fixture_file_upload method to fake the attachment uploads. My tests intermittently give me the error below (or one similar to it), generated by a factory_girl call to create the object containing the attachment, which is in my setup block. @...

Rails - problem with HABTM

Hello everyone. I have two models: ItemType and PropertyType, they are connect with HABTM relation. But this code doesn't work: PropertyType.find(:all, :conditions => ["item_type_id != ?", existing_type_id]) I have error: Mysql::Error: Unknown column 'item_type_id' in 'where clause': SELECT * FROM `property_types` WHERE (item_type...

Is there an easy way to have backgroundrb started with server?

Is there an easy way to have backgroundrb started (restarted) when the server reboots? Ex. What if your hosting use mongrel cluster and you have no access to it (except start/stop) One of solution i found on forums is code snippet in backgroundrb plugin with check for PID exist (if not exist start with exec or system) etc. Just your id...

Could not find RubyGem mloughran-api_cache (>= 0)

I'm getting this error trying to do a rake db:migrate --> Could not find RubyGem mloughran-api_cache (>= 0) Not I know that's a gem missing, But for some reason I can't find the whereabout of that gem. It's no the gem called api_cache. Or at least if it is, the system does not recognized that it is installed. Any help would be really a...

Rails app in a subdirectory

Trying to set up a Rails app in a subdirectory. My server is Cherokee. I have a base url of: www.nonsense.com, which is a wordpress blog, and I wish to set up a rails app in, www.nonsense.com/rails_app. A quick scan of google led me to using: ActionController::AbstractRequest.relative_url_root = "/rails_app" However, it seems this has...

date_select tag doesn't get stored in my rails app

Hi there, I'm trying to let the user select his birthday with: <% form_for :user, :url => users_path do |f| %> <%= f.date_select :birthday, :start_year => 2010 , :end_year =>1920, :discard_day => true %> <% end %> The problem is that it doesn't get saved... birthday is a date field in the users table and to save it I call @user =...

get 5 random favorites from flickr

Hello! I need to retrieve 5 random favorites photos from a flickr profile. I've got perfect Moonpix-Flickr Gem to work with Flickr API. And it works great, by using method .favorites I can get full list of user's favorites photos. It returns as Flickr::PhotoCollection and I don't know how to get 5 random records from it. Thanks in a...

rails gems in netbeans

I have installed rails gems in netbeans(on windows). However when I run the app, it says it cannot connect to the server. For example for ruport, I had these lines in environment.rb file. Rails::Initializer.run do |config| config.after_initialize do require "ruport" end end config.load_paths += %W( #{RAILS_ROOT}/app/reports ...