How can I handle a parameter passed in from a raw HTML form?
in /views/feeders/index.html.erb:
<form action="/feeders/extract/" method="post" accept-charset="utf-8">
<input type="text" name="url" value="" id="url">
<p><input type="submit" value="submit"></p>
</form>
in /controllers/feeders_controller.rb
class FeedersController < ApplicationController
def index
@url=params[:url]
end
def show
end
def extract
@url=params[:url]
redirect_to :controller => 'feeders', :action => 'show'
end
end
in routes.rb:
root :to => 'feeders#index'
match '/feeders/extract/:url' => 'feeders#extract', :via => :post
match '/feeders/show/' => 'feeders#show'
I keep getting
Routing Error
No route matches [POST] "/feeders/extract"
point #1
make your route as
your route
match ‘/feeders/extract/:url’ => ‘feeders#extract’, :via => :post
will allow urls like
Try “rake routes” to know more
point #2: after you have followed #1 above
As I am trying to understand your needs from your comments, what you need is as below
in your routes.rb
and then perhaps you wont need extract action in your FeedersController.rb, show action would get called for extract call with params[:url]
point #3(alternative to #2): after you have followed #1 above
simply edit your controller as
instead of redirect there
Hence you can go with either #1,#2 or #1,#3 as per your needs.
You should go with #1,#2 if “extract” action/process has more meaning there, I mean to end user.
Hope I understood your scenario 🙂