# Calling a controller action from another controller

**URL:** <https://www.ruby-forum.com/t/calling-a-controller-action-from-another-controller/176260>\
**Category:** Rails\
**Created:** [September 28, 2009, 6:28am UTC](https://www.ruby-forum.com/t/calling-a-controller-action-from-another-controller/176260 "2009-09-28T06:28:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrgoodner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jrgoodner](https://www.ruby-forum.com/u/jrgoodner)\
**Post date:** [September 28, 2009, 6:28am UTC](https://www.ruby-forum.com/t/calling-a-controller-action-from-another-controller/176260/1 "2009-09-28T06:28:07Z")

</div>

Hey there, I’d like to set up my application so that, upon  
successfully creating a new user (within the users controller), that  
user is automatically logged in. So this is what I figured might  
work, but it doesn’t:

## 

## def create @user = User.new(params[:user]) … if @user.save … redirect\_to(:controller =\> ‘sessions’, :action =\> ‘create’, :login =\> @user.login, :password =\> @user.password) else … end

I get an error to the tone of “non-existent action.”

Any ideas? Should I post my sessions\_controller code?

Thanks in advance, I hope I’ve provided enough info.

Best,  
Jared

---

<div class="post-metadata">

**Author:** ![jrgoodner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jrgoodner](https://www.ruby-forum.com/u/jrgoodner)\
**Post date:** [September 28, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/calling-a-controller-action-from-another-controller/176260/2 "2009-09-28T13:00:07Z")

</div>

jrgoodner wrote:

> Hey there, I’d like to set up my application so that, upon  
> successfully creating a new user (within the users controller), that  
> user is automatically logged in. So this is what I figured might  
> work, but it doesn’t:
> 
> --------------------------- def create @user = User.new(params[:user]) ... if @user.save ... redirect\_to(:controller =\> 'sessions', :action =\> 'create', :login =\> @user.login, :password =\> @user.password) else ... end ----------------------------- I get an error to the tone of "non-existent action."

That should work, I think. Is create defined in SessionsController?

> Any ideas? Should I post my sessions\_controller code?
> 
> Thanks in advance, I hope I’ve provided enough info.
> 
> Best,  
> Jared

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
