User Input from Ruby on Rails form -
im trying grab users input value (:url) in rails app. believe its
params[:user_input]
but dont know how implement controller. place anywhere or in specific method?
method
def index @posts = post.all embedly_api = embedly::api.new :key => '', :user_agent => 'mozilla/5.0 (compatible; mytestapp/1.0; my@email.com)' url = params[:user_input] @obj = embedly_api.extract :url => :user_input end
how can user_input url can pass hash???
the params
hash contains mapping of names of html form controls values provided user. access each 1 params[key_name]
.
in case, think want create local variable out of params[:url]
. that's fine. use this.
def index @posts = post.all embedly_api = embedly::api.new :key => '', :user_agent => 'mozilla/5.0 (compatible; mytestapp/1.0; my@email.com)' url = params[:url] @obj = embedly_api.extract :url => url end
however, local variable isn't necessary, make code more succinct removing local variable , doing instead:
@obj = embedly_api.extract :url => params[:url]
Comments
Post a Comment