# About action create

**URL:** <https://www.ruby-forum.com/t/about-action-create/132859>\
**Category:** Rails\
**Created:** [March 25, 2008, 11:55am UTC](https://www.ruby-forum.com/t/about-action-create/132859 "2008-03-25T11:55:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 25, 2008, 11:55am UTC](https://www.ruby-forum.com/t/about-action-create/132859/1 "2008-03-25T11:55:47Z")

</div>

there i hava a model named Person  
the controller is People  
in the new.html.erb file function form\_for(@person) make the start  
form tag #@person=Person.new

i think it’ll call “create” action in PeopleController when invoke  
submit button  
but not!  
it just renders index.html.erb and never access to action create

sorry to my poor English 😃  
wish i hava descriped it clearly…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 25, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/about-action-create/132859/2 "2008-03-25T19:28:05Z")

</div>

Your  
@person = Person.new  
should be in the people\_controller…

I’d say start with a new rails project…

Generate a scaffold for your person model

→ ruby script/generate scaffold person last\_name:string  
first\_name:string dob:datetime

look at the source that is written for you, i.e., new.html.erb has

→ \<% form\_for(@person) do |f| %\>  
 → … field stuff…  
 → \<%= f.submit “Create” %\>  
 → \<% end %\>

setup your database, and all that… then browse to  
[http://localhost:3000/people](http://localhost:3000/people) - click the “New person” link, and look  
at the page source if you’re curious

add a person, fill out the fields and submit. That should hit your  
people\_controller create method (it’s a POST, after all).

While not necessarily how you’ll end up writing your app in the future,  
the scaffolded code is a great resource to read in the beginning to see  
how Rails fits it all together.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 26, 2008, 4:12am UTC](https://www.ruby-forum.com/t/about-action-create/132859/3 "2008-03-26T04:12:33Z")

</div>

thx ! here is my source code .  
PeopleController  
def new  
@person=Person.new  
end  
def create  
@person = Person.new(params[:person])

```
respond_to do |format|
  if @person.save
    flash[:notice] = 'Product was successfully created.'
    format.html
    format.xml { render :xml => @person, :status

```

=\> :created, :location =\> @product }  
else  
flash[:notice]=“dont saved”  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @person.errors, :status  
=\> :unprocessable\_entity }  
end  
end  
end

new.html.erb  
\<% form\_for(@person) do |f| %\>  
\<%=f.text\_field :first\_name %\>  
…  
\<%end%\>

something wrong here ?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 26, 2008, 4:32am UTC](https://www.ruby-forum.com/t/about-action-create/132859/4 "2008-03-26T04:32:35Z")

</div>

i guess there is something wrong with ROUTER

first i insert data items to mysql database via PHPMYADMIN,  
the INDEX method show out them  
but when i click the â€œshow,edit,destroy"links  
rails give me the response “No action responded to 1” the number is  
person id.  
anyone can tell my why?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 26, 2008, 4:39am UTC](https://www.ruby-forum.com/t/about-action-create/132859/5 "2008-03-26T04:39:01Z")

</div>

Yes!just the ROUTER.rb!  
here is the code  
map.resources :people

# Install the default routes as the lowest priority.

map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:id.:format’  
at the beginning i put “map.resources :people” on the end .  
i think this cause something wrong
