# Find id of newly created object

**URL:** <https://www.ruby-forum.com/t/find-id-of-newly-created-object/185811>\
**Category:** Rails\
**Created:** [March 26, 2010, 3:45pm UTC](https://www.ruby-forum.com/t/find-id-of-newly-created-object/185811 "2010-03-26T15:45:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![droopy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/47e85d/32.png) [@droopy](https://www.ruby-forum.com/u/droopy)\
**Post date:** [March 26, 2010, 3:45pm UTC](https://www.ruby-forum.com/t/find-id-of-newly-created-object/185811/1 "2010-03-26T15:45:47Z")

</div>

Hi there,

I’m kind of a newbie, so pardon me if this is obvious

I’m developing an app that has to accept creation of records from http  
requests such as  
[http://my.domain.com/in/?text=some+text@alias=myName](http://my.domain.com/in/?text=some+text@alias=myName)

So I have this route :  
map.connect ‘/in’, action: ‘incoming’

and this action in the controller (mostly borrowed from scaffold)

def incoming  
@message = Message.new  
@message.text = params[:text]  
@message.sender = params[:alias]  
respond\_to do |format|  
if @message.save  
format.html # incoming.html.erb  
format.xml { render :xml =\> @message }  
end  
end  
end

and a small view to acknowledge incoming message  
incoming.html.erb

Incoming message #\<% @message.id %\> from \<%= @message.sender %\>

Problem is I never get back the @message.id.

I always get something like:

Incoming message # from myName

Any thoughts ?

Thanks,

Christophe

---

<div class="post-metadata">

**Author:** ![droopy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/47e85d/32.png) [@droopy](https://www.ruby-forum.com/u/droopy)\
**Post date:** [March 26, 2010, 4:02pm UTC](https://www.ruby-forum.com/t/find-id-of-newly-created-object/185811/2 "2010-03-26T16:02:46Z")

</div>

On Fri, Mar 26, 2010 at 7:44 AM, Christophe D.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> and a small view to acknowledge incoming message  
> incoming.html.erb
> 
> Incoming message #\<% @message.id %\> from \<%= @message.sender %\>
> 
> Problem is I never get back the @message.id.

Copy/paste error, or are you missing an ‘=’ sign there?  
#\<%= @message.id %\>

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![droopy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/47e85d/32.png) [@droopy](https://www.ruby-forum.com/u/droopy)\
**Post date:** [March 26, 2010, 4:17pm UTC](https://www.ruby-forum.com/t/find-id-of-newly-created-object/185811/3 "2010-03-26T16:17:24Z")

</div>

Thanks,

I’m so stupid…  
Can’t understand how I missed that

Christophe  
Le 26 mars 2010 à 16:01, Hassan S. a écrit :
