ruby-on-rails

In Rails why can't I use reset_session or any of my methods in application_controller within my tests?

I tried to use reset_session in my test code but it complains no method found. I also tried to use some of the authentication methods ive written in my tests and they produced no method errors too (they are in my application_controller ) Can someone help to explain if a) this is a problem experienced by all and not just me b) a workar...

How to import existing ROR project ?

Hey, I'm new to Ruby on Rails (PHP developer here) and I need to edit an existing ROR project. I've been using Aptana Studio for my PHP projects (switched to Zend after Aptana 2.0) but I've kept Aptana RadRails for my ruby projects. So what I want to do is to get the ROR project from the server (it's hosted on some linux machine) and i...

How to test email sending using Rspec?

What are the best practices and tools to test email-sending using rspec with Rails? For instance, how do I test that an email has been sent or what should I test to have efficient testing and acceptable coverage. If you guys need an example, how would I go and test this: class UserMailer < ActionMailer::Base def jobdesc_has_been_re...

Ruby: Problem using passenger

Hi, i first installed mod_ruby on my debian and afterwards ( after figuring out that it was too slow ) i wanted to chagne to passenger for my apache Now i've got the problem, that the passenger is successfully loaded by the apache, but is not used, even though i configured everything correctly, like: <VirtualHost *> ServerAdmi...

How can we delete rows from a join table by using ActiveRecord ?

create_table "tags_pages", :id => false do |t| t.integer "tag_id", "page_id" end add_index "tags_pages", "tag_id" add_index "tags_pages", "page_id" How activerecord works on this table ? I want to insert and delete new rows. Sorry if it is a noob question. ...

RoR: Destroy association with has_many, :through if orphaned

Given Ryan Bates's great tutorial on Virtual Attributes, how would I go about destroying a Tag (not Tagging) if, once the article is destroyed, that Tag is no longer used? I tried doing something like this: class Article < ActiveRecord::Base ... after_destroy :remove_orphaned_tags private def remove_orphaned_tags tag...

Ruby Based Blogging Engine

What Rack enabled blogging engines exist? I want to deploy a free blog to heroku and need more customizabilty than the free hosting of Wordpress.com or Blogerty provide. Also in another note, has anyone tried to port Wordpress to Ruby? ...

rails console won't always call accessor override specified in model

I have a simple model: class Person < ActiveRecord::Base def dob=(dobstr) raise "oops" end def virtualdob= raise "virtual oops" end end dob is a table column. When I try to set it from a view, it correctly crashes ... but when I try to set it via the rails console, it never gets called... but calling the virtual att...

RoR: How to Change fields on Join statement generated by Active Record's sum function.

I'm doing a sum using the Sum function provided by RubyOnRails' Active Record as follows: s=DatosMateria.sum('inscritos',:conditions=> "datos_materia.ano=2005 AND materias.codigo=2394",:include=>"materias") it returns 0 and generates me the following SQL statement: SELECT sum('datos_materia'.inscritos) AS sum_inscritos FROM 'datos_m...

Rspec: undefined method `new' error in ActiveRecord model

I know this has to be something stupid, but I keep getting the following error in one of my examples: undefined method `new' for #<Class:0x211d274> I have created a simple example to show the error: describe LateCharge do before :each do @membership = Membership.new @location = mock_model(Location, :late_payment_rate => 10)...

Ruby on Rails Problems with Views (rhml / html.erb)

Hi, I'm having a problem with regards to views in ruby on rails. Basically I have a regular project which lists the details just fine on http://localhost:3000/stores/ which loads the code found within index.html.erb Now, i have scaffolding etc all in place, however when i try to load http://localhost:3000/stores/search which SHOULD...

How to configure and run multiple test environments in rails 2.3.4

Hello, I am trying to add and additional test environment to a rails 2.3.4 project. I have added the proper db configuration into database.yml and I have created a file with the name of the environment in the environments directory which is a basically copy of test.rb. The new environment is named test_ci. When I run all tests using th...

Rails - authenticate_or_request_with_http_basic custom "access denied" message

I'm struggling myself trying to change that default message once you insert invalid credentials as username:password on rails using authenticate_or_request_with_http_basic. For example if I make a curl request on a method that need this authentication, once I insert the wrong username and password it returns HTTP Basic: Access denied. ...

How do I create a persistent table in a Rails app's test database?

I have a rails app that references the TMY3 meteorological dataset, which is a ton of different hourly weather observations for over 1000 different sites. I downloaded the entire dataset and sucked the columns I need into a local table that is indexed by site, which makes it nice and fast in dev and in production. However, the indexi...

Automatic Login with Rails?

Hey there, I am trying to get up a simple authentication system with Rails' Restful-Authentication plugin, and am just wondering how it works, b/c I can't seem to figure out what the requirements are for cookies, and how to make it so the browser always remembers you (for 6+ months). Few questions: 1) How do you do remember_me's for r...

Google Maps Add a Marker to Map, then Store Latitude and Longitude in Ruby on Rails

I've had a look at the previous questions asked but i cannot quite seem to fit this in so here it is: Basically, I have a Ruby on Rails project and i would like to have a page where the user pin points his location on a google map by adding a marker (only 1 should be permitted) and then store the longitude and latitude within the Ruby o...

Dealing with expected nils

I expect to see a nil returned with the following embedded Ruby: <%=h [@inventory.origin.code] %> it returns a "NoMethodError nil object". However when an object is in fact present, it functions just fine (as expected). Therefore I created this test (following this advice): <b>origin_id:</b> <% if (@inventory.origin.code.nil? or @...

Adding my comments to the index view...Ruby on Rails

Ok...I am new to rails so this may be a stupid question but need help. I just watched and implemented Ryan Bates screencaset about setting up a blog. You can see it here http://media.rubyonrails.org/video/rails%5Fblog%5F2.mov. Here is the skinny: Two tables: Posts and Comments. Everything works great including the addition of comments v...

Multiple views in Rails

I have the following problem: In Rails I have two Objects: Categories and Items One category has many items and one item belongs to one category. Okay. There are no problems. But now, I want to display all existing categories in a sidebar on every page in my project. I tried to do display them like: <div class="sidebar"> <% @catego...

Controller specs in isolation mode and render :update

Hi folks, I am using RSpec for writing my controller tests/specs. I faced the problem, that the following code gets rendered: render :update do |page| page['middle_content'].replace_html :partial => "admin/pages/show" end Isolation mode is the default, isn't it? How can I fix this or am I doing something wrong? Here is for examp...