# Getting Parameter when Form\_for is Submitted

**URL:** <https://www.ruby-forum.com/t/getting-parameter-when-form-for-is-submitted/189914>\
**Category:** Rails\
**Created:** [June 9, 2010, 8:43pm UTC](https://www.ruby-forum.com/t/getting-parameter-when-form-for-is-submitted/189914 "2010-06-09T20:43:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [June 9, 2010, 8:43pm UTC](https://www.ruby-forum.com/t/getting-parameter-when-form-for-is-submitted/189914/1 "2010-06-09T20:43:05Z")

</div>

This is slightly tied with my previous post. I wasn’t sure if I was  
supposed to make another message in there, so I made a new post.

So in my previous post I accidentally asked a pure ruby question about  
gsub which I’ll be using in this question.

Anyways, what I want to do is to take a single parameter from user’s  
input in the Form\_for and run it through the gsub code [ @file\_cut =  
order.gsub(/[\w ! # $ % ^ & \* + -]+.doc$/, '\*.doc) ] when the user  
submits the form. The parameter will still be stored in the database  
so I don’t think test\_field\_tag, etc. will help me unless you think  
otherwise. Also, I’m hoping not to use javascript in my code.

Here’s my code:

## orders\_controller.rb

class OrdersController \< ApplicationController

# GET /orders

# GET /orders.xml

def index  
@orders = Order.all

```
respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @orders }
end

```

end

# GET /orders/1

# GET /orders/1.xml

def show  
@order = Order.find(params[:id])

```
#@try = params[:file]
# A failed attempt

respond_to do |format|
  format.html # show.html.erb
  format.xml { render :xml => @order }
end

```

end

# GET /orders/new

# GET /orders/new.xml

def new  
@order = Order.new

```
respond_to do |format|
  format.html # new.html.erb
  format.xml { render :xml => @order }
end

```

end

# POST /orders

# POST /orders.xml

def create  
@order = Order.new(params[:order])

```
#order = params[:file]
#@file_cut = order.gsub(/[\w ! # $ % ^ & * + -]+\.doc$/, '*.doc)
#have tried to implement the code here

respond_to do |format|
  if @order.save
    format.html { redirect_to(@order, :notice => "Order was

```

successfully created.") }  
format.xml { render :xml =\> @order, :status  
=\> :created, :location =\> @order }  
#/display  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @order.errors, :status  
=\> :unprocessable\_entity }  
end  
end  
end

# DELETE /orders/1

# DELETE /orders/1.xml

def destroy  
@order = Order.find(params[:id])  
@order.destroy

```
respond_to do |format|
  format.html { redirect_to(orders_url) }
  format.xml { head :ok }
end

```

end  
end

## new.html.erb

# New Order

\<% form\_for(@order) do |f| %\>  
\<%= f.error\_messages %\>

\<%= f.label :name, "Your N." %\>  
 \<%=h f.text\_field :name %\>

\<%= f.label :file%\>  
 \<%=h f.file\_field :file%\>

\<%= f.label :email, "Your Email" %\>  
 \<%=h f.text\_field :email %\>

\<%= f.submit 'Create' %\>

\<% end %\>

\<%= link\_to ‘Back’, orders\_path %\>

Thank you for taking the time to read,  
Anon\_comp
