actioncontroller

Rails equivalent of respond_to |format| with a straight render

I'm working with ActiveResource a lot so my service models are only using XML. Thus, I have no need for a respond_to block, I literally just render :xml => @model I can't however figure out how to render a 404 header using this. I've had to resort to respond_to, which I think adds a few unnecessary method calls. Here's what I'm using...

Why is Rails before_filter called twice when the controller is subclassed?

I'm at Rails 2.3.5 and I have this problem: class BaseController < ApplicationController before_filter :foo, :only => [:index] end class ChildController < BaseController before_filter :foo, :only => [:index, :show, :other, :actions] end The problem is that on ChildController, the :foo before filter gets called twice. I've tried ...

How do I include Responder in ActionController::Metal in Rails 3?

I'm working a Rails 3 controller that has a very specific, limited purpose, and all I need is for it to respond_to :json. This screencast says my controller can inherit from ActionController::Metal, and then just include the functionality I need to make things faster: http://rubyonrails.org/screencasts/rails3/action-controller When my...

How can I access UrlWriter url/path generators from a model's class method?

I want to generate urls from a model's class method. I've done this before from an instance method by simply including ActionController::UrlWriter -- I tried including this in the instance definition scope and also the class definition scope, to no avail. class Foo < ActiveRecord::Base # only works for instance methods # include Act...

ActionController::InvalidAuthenticityToken ocurring only in Firefox and in production mode on apache+passenger

Hello, With one of my forms, the ActionController::InvalidAuthenticityToken is occurring after the form is sent to the proper controllers "create" method. The thing is that there actually is a valid authenticity token included and the error only occurs in Firefox. Other browsers work fine. I tried to skip the verification of the auth t...

Setting up actions for the ActionController in Rails

I just issued a [ script/generate scaffold User ] command to generate my files. All the CRUD pages work well so that's good and now I'm trying to create more pages. I create a method in the user_controller.rb file as follows: def login #blahblah end Then created app/views/users/login.html.erb for the view. When I tried accessing it t...

How to get all models,controller,action and method names in Rails

Hi guys, In runtime we can get the current controller and current action names by controller_name and action_name methods like wise, I want to get all the remaining controllers and action names and models too if possible.. Any rails method available to get all the controller names and the action names in application controller. ...

actionlistener returning a nullexception on jbutton

I have an action listener set up on my main jframe menu for the buttons listed on it, and they work fine, bringing up other jframes as needed. The problem is when a person clicks the buttons on the jframes brought up I get a nullexception after a jbutton is clicked on that submenu jframe. Example code: public class main extends JFrame...

after_filter for exceptions

Is there something similar to an after_filter that still runs if the action raises an exception? I'm using an external logger (since I'm on Heroku); the response headers are filtered and logged in the after_filter. If an exception is raised, the filter doesn't run, and I don't have a log of the response header data. If I try to hook i...

How to determine which view to render in a controller action

Okay, I have a few different of ideas of how I would achieve this, but thought I would ask here in case someone has a better solution. I have a SessionsController that has a login view and a widget_login view. I was wondering how to go about determining which view to render in the new action of SessionsController. Right now, everythin...

SqlSessionStore in Rails 3

I am migrating an existing application from Rails 2 to Rails 3. In the old environment file, SqlSessionStore was set up with: ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:database_manager => SqlSessionStore) SqlSessionStore.session_class = MysqlSession When trying to start my application in Rails 3, I'm told: DEPRECA...

What is the most Rails'ish way of handling multiple layouts/views for the same controller action?

The scenario is this: I have some users on my site. A user has a role, the relevant ones here is admin and normal. I also have a model, let's call it SomeModel. I have created a backend for the site, which uses an admin layout. All admins have full access to edit any content. The problem arises with this relation: User -> owns -> Some...

FInding out which before_filters are already set in Rails 3

I have a DSL for controller configuration. The underlying functionality relies on before_filters. To prevent setting the before_filter more than once, I really need to find out whether a before_filter is already set in a Rails 3 controller. Since before_filter work different from class variables (inheritance, class reloading), I cannot...

Migrating from Rails 2 to Rails 3 problem (nil.any?)

I've been upgrading my app from Rails 2.3.8 to Rails 3. After getting all the basic stuff done (configs, routes, and the new AR API, replacing Authlogic with Devise) and getting some mostly static pages to show up fine I get an error in the rest of my site: You have a nil object when you didn't expect it! You might have expected an ins...

set default_url_options on initialize

I need to force the host in one of the environments in my rails app. I've can get the override to work by including def default_url_options(opts={}) opts.merge({:host => 'stg.my-host.com'}) end in app/controllers/application.rb But is there a way to set this on initialize, preferably in a config/environments/... file? I'd li...

Rails 3- fixing juggernaut involving template and JS generator

Hi, I'm using the original Juggernaut (not Juggernaut 2) with Rails 3. In the lib/juggernaut.rb, it breaks due to not being able to find @template. According to this other post, @template is not provided in controllers in Rails 3. How can I fix the following code, so that it can run smoothly with Rails 3? (Here's a link to the origin...