ruby-on-rails

How to test link_to_unless_current in RSpec view example group

I'm learning RSpec 2 with Rails 3 and while it's been going along quite nicely so far, I'm having a problem testing the helper link_to_unless_current in a view. What I've been trying to do is use a simple assert_select from a view spec to determine if a link is being generated in the following partial view (HAML): %article.post{ :id => ...

Format javascript date to match rails format

I get a date back from rails that looks like: "2010-10-29T00:00:00+00:00" And I'd like to convert a javascript date created by 'new Date()' to that format. Is there an easy way? ...

Sorting selects within Ruby On Rails

Hi ROR newby question: I've got a controller with the following action: # GET /organisations/new # GET /organisations/new.xml def new @organisation = Organisation.new @organisationtypes = Organisationtype.find(:all) respond_to do |format| format.html # new.html.erb format.xml { render :xml => @organisation } end end...

railstutorial.org - undefined method `Factory'

Hi there, I'm attempting to follow railstutorial.org, and am currently on Chapter 7, where you start using factories: http://railstutorial.org/chapters/modeling-and-viewing-users-two#sec:tests_with_factories I'm using Rails 3.0.1 and ruby-1.9.2-p0 I can't for the life of me get my rspec tests to pass though, the error i get is Failu...

Help understand validates_each Rails helper

class User < ActiveRecord::Base validates_each :name, :email do |model, attr, value| if value =~ /groucho|harpo|chico/i model.errors.add(attr, "You can't be serious, #{value}") end end end Confused as to how this works. Is :name, email the items it will loop? ...

Saving multiples of the same object within Ruby On Rails

Hi I've got an organisation database table which holds the following fields: organisationid, organisationname, organisationaddressid, mainadminname, mainadminaddressid. The two address ids are pointers to two records within the address database table. The address database table conatins the following fields: addressid, addressline1...

How Do Rails Controllers Share Instance Variables with Views?

I am fairly new to Rails, but I am pretty experienced with Ruby. Can somebody tell me how Rails makes instance variables from a controller available to views. How did the Rails team go about implementing this? ...

Extending onclick argument of button_to_remote in rails

Hi! I would like to extend my onclick parameter of button_to_remote with another javascript function call, but i couldn't find any answer for that. So i have sg like this: button_to_remote('>', :url => {:action => "show_dtree", :id => tree_child.id, :dir1 => dir11, :dir2 => dir12} what generates the following code: <input onclick="n...

Rails: How do you render with a layout inside a JS template?

I'm familiar with using Ajax templates to update particular parts of a page, but how do you render with layout when doing so? For example, given a layout: #foo = yield :foo a simple view "show.html.haml": = render @bar and a partial: - content_for :foo = bar.to_html ... the HTML result would render within the layout and I'd...

Authenticating a user after #create

This seems to keep coming up for me on various projects and I'm wondering if anyone out there has a great solution: We have a Rails app with Authlogic authentication. Initially, there's a nice, clean, RESTful ListingsController that requires a user to be logged in before they can post/create: before_filter :require_user, :only => [ :ne...

In rails is it possible to get colour highlighting for the rake test command?

When running the rake test command from the terminal within a rails 3 project directory, the test result output is not coloured. Hence it cannot be interpreted at a glance. Is there a way of getting colourised output for the results, as you can get in rspec? >rspec --colour ...

Ruby on Rails will paginate routes

Hi, I am trying to set up my routes for the will paginate plugin so I don't have ?page=1 at the end of the url, and so I can later try to use page caching. I've been browsing around online and I found a few tutorials explain to use map.connect, however, I am having trouble getting it to work with my application. Here's an example url:...

Rails: variable access: from ApplicationController to ActionView

How do I access in an ActionView a variable, that has been defined in the ApplicationController? In my case, I'd like to make my layout respond to a variable that's been set-up in the ApplicationController. If it were a view, associated with a controller's action, I'd only need to set-up an instance var in the corresponding action and ...

Rails 3 - Suggests on a model for Photos

Hello, I'm looking for suggestions on creating a model/scaffold for Photos I want a user to be able to create a album that contains 1 or more photos. Current idea: album id, name, user_id photos id, name, album_id Thoughts? Thanks ...

In Rails, what exactly do helper and helper_method do?

I was able to find some docs in apidoc.com but can't tell what exactly helper does. helper_method seems more straight forward: to make some or all of the controller's methods available for use to the View. What about helper? Is it to do the other way around: import helper methods in a file or in a Module? (Maybe the name helper and h...

Static pages in Rails?

So I'm wondering what the best way to do static pages in Rails is, or rather Rails 3. I've always been a little confused about this, like should I create a controller or not? ...

Rails 3 - AJAX Redirect? Pass class from Controller to View for AJAX

Hello, Here's what I'm trying to do... Controller def create . . if @project.save format.js { @project } end end View window.location = "<%= redirect_to(@project, :notice => 'Project was successfully created.') %>"; In Sum,using AJAX to create a project. When the create is done, I want to redirect the user to the project.....

Rails - Creating a Landing Page, which is different than the Web App

Hello, I'm rails I've been building a web app. But the web app is completely different than what the landing page (sign in, register, about, etc should look like) How do rails developers handle this? Different layouts? Different CSS files? etc.. what's cleanest? Thanks ...

Utilizing A Devise Session Through Flex With Rails3-AMF

I have a Flex front end and a Rails 3 back-end that I would like to establish a session to. Before you can access the page embedded with the flex front-end, you are prompted with a html login page through Devise. I am able to login fine through the html page but cannot get access to the session with Flex using amf requests. I have the...

Rails: Displaying different view for the same URL?

First, an example of what I'm trying to do: If you go to http://www.meetup.com and you are not signed in, you see a page that shows 'Do something • Learn something...' etc. which is a public page But when you are logged in, that same page (URL) shows 'Welcome, xxx...Whats happening...' etc. which is specific to you.That is what I'm try...