# What / when calls create function in an ActionController?

**URL:** <https://www.ruby-forum.com/t/what-when-calls-create-function-in-an-actioncontroller/161578>\
**Category:** Rails\
**Created:** [February 27, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/what-when-calls-create-function-in-an-actioncontroller/161578 "2009-02-27T16:25:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSZSmSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@SSZSmSS](https://www.ruby-forum.com/u/SSZSmSS)\
**Post date:** [February 27, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/what-when-calls-create-function-in-an-actioncontroller/161578/1 "2009-02-27T16:25:37Z")

</div>

Hi friends ,

i am newbie and was trying to learn rails by following a tutorial  
which uses attachment\_fu to upload videos .! every thing was working  
till i edited something somewhere ! the problem is that nothing  
happens when i click the submit button

the new.html.erb is as follows and it displays well too

## Upload Advertisements 1
  

\<% form\_for(@advertisement, :html =\> { :multipart =\> true }) do |f| %\>  
\<%= f.error\_messages %\>

| \<%= f.label :title %\>: | \<%= f.text\_field :title %\> |
| \<%= f.label :description %\>: | \<%= f.text\_area :description %\> |
| \<%= f.label :advertisement %\>: | \<%= f.file\_field :uploaded\_data %\> |
| \<%= f.submit 'Submit' %\> - \<%= link\_to 'Back', advertisements\_path %\> |

\<% end %\>

and the create function in the Controller is as follows

def create

```
@advertisement = Advertisement.new(params[:advertisement])

#@advertisement.write_to_log

if @advertisement.save
   @advertisement.convert
   flash[:notice] = 'Advertisement has been uploaded'
   redirect_to :action => 'index'
else
   @advertisements = Advertisement.find(:all)
   render :action => 'new'
end

```

end

even deleting the create function , it shows no error but returns to  
index page when submit button clicked . it seems that this function is  
not called properly

help appreciated  
thanks in advance

---

<div class="post-metadata">

**Author:** ![SSZSmSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@SSZSmSS](https://www.ruby-forum.com/u/SSZSmSS)\
**Post date:** [February 27, 2009, 4:37pm UTC](https://www.ruby-forum.com/t/what-when-calls-create-function-in-an-actioncontroller/161578/2 "2009-02-27T16:37:25Z")

</div>

> even deleting the create function , it shows no error but returns to  
> index page when submit button clicked . it seems that this function is  
> not called properly

Have you set up your routes.rb file?

SH

---

<div class="post-metadata">

**Author:** ![SSZSmSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@SSZSmSS](https://www.ruby-forum.com/u/SSZSmSS)\
**Post date:** [February 27, 2009, 5:20pm UTC](https://www.ruby-forum.com/t/what-when-calls-create-function-in-an-actioncontroller/161578/3 "2009-02-27T17:20:25Z")

</div>

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html](http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html)

example taken form the above link:

# Note: a @person variable will have been created in the controller.

# For example: @person = Person.new

\<% form\_for :person, @person, :url =\> { :action =\> “create” } do |f|  
%\>  
\<%= f.text\_field :first\_name %\>  
\<%= f.text\_field :last\_name %\>  
\<%= submit\_tag ‘Create’ %\>  
\<% end %\>

what you got is this:  
\<% form\_for(@advertisement, :html =\> { :multipart =\> true }) do |f|  
%\>  
\<%= f.text\_field :title %\>  
\<%= f.text\_area :description %\>  
\<%# … %\>  
\<%= f.submit ‘Submit’ %\>

now try changing your first line to:  
\<% form\_for :advertisement, @advertisment, :url =\> { :action =\>  
“create” }, :html =\> { :multipart =\> true } do |f| %\>

hope this helps.

---

<div class="post-metadata">

**Author:** ![SSZSmSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@SSZSmSS](https://www.ruby-forum.com/u/SSZSmSS)\
**Post date:** [February 28, 2009, 5:11am UTC](https://www.ruby-forum.com/t/what-when-calls-create-function-in-an-actioncontroller/161578/4 "2009-02-28T05:11:49Z")

</div>

My routes.db

ActionController::Routing::Routes.draw do |map|

map.resources :advertisements

map.root :controller =\> “home”  
map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:id.:format’  
end

---

<div class="post-metadata">

**Author:** ![SSZSmSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@SSZSmSS](https://www.ruby-forum.com/u/SSZSmSS)\
**Post date:** [February 28, 2009, 10:12am UTC](https://www.ruby-forum.com/t/what-when-calls-create-function-in-an-actioncontroller/161578/5 "2009-02-28T10:12:51Z")

</div>

> how can i know weather it is called or not

set a debugger.

---

<div class="post-metadata">

**Author:** ![SSZSmSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@SSZSmSS](https://www.ruby-forum.com/u/SSZSmSS)\
**Post date:** [February 28, 2009, 2:32am UTC](https://www.ruby-forum.com/t/what-when-calls-create-function-in-an-actioncontroller/161578/6 "2009-02-28T02:32:36Z")

</div>

i tried \<% form\_for :advertisement, @advertisment, :url =\> { :action  
=\>  
“create” }, :html =\> { :multipart =\> true } do |f| %\>

but the result is the same !

will on clicking the submit button automatically call the create  
function?  
how can i know weather it is called or not
