ruby on rails - How do I submit a form's parameters into a (API call) method in my controller? -


i making api call not saving of data database, assumed not need make model purpose. however, not know how generate form api call, in controller.

here form in view:

<%= simple_form_for ithinkineedsomethinghere url: searchapis_path, :method => 'get' |f| %>   <%= f.input :keyword, :placeholder => 'keyword', input_html: { name: :keyword } %>   <%= f.input :city, :placeholder => 'city', input_html: { name: :keyword } %>   <%= f.input :start_date, :placeholder => 'yyyy-mm-dd', input_html: { name: :start_date } %>   <%= f.input :end_date, :placeholder => 'yyyy-mm-dd', input_html: { name: :end_date } %>   <%= f.button :submit, "submit" %> <% end %> 

my corresponding controller:

class homecontroller < applicationcontroller   def index   end    def searchapis     start_date = params[:start_date]     end_date = params[:start_date]     keyword = params[:keyword]     city = params[:city]      eventbrite_request = typhoeus::request.new('https://www.eventbriteapi.com/v3/events/search?q='+keyword+'&sort_by=best&venue.city='+city+'&start_date.range_start='+start_date+'t00:00:00z&start_date.range_end='+end_date+'t00:00:00z',                                   method: :get,                                   headers: { 'authorization' => env['eventbrite']})     @response = eventbrite_request.run      # yelp_request = typhoeus::request.new('',     #                                   )     # set @result data want.   end   end 

i getting "undefined method 'model_name'" error.

the route making request /searchapis, guessing url in form should searchapis_path.

so far have learned how make form generate new instance of model, in case, form initiate api call, response later display under form. it's worth, want later able save select data response json 'bookmarks' model.

thanks.

where wrote ithinkineedsomethinghere record, typically activerecord model, goes. used in construction of various field names.

since looks you're doing search controller, put :search there, make form fields named things search[keyword]

on backend then, have access proper params object, typically nested under whatever named record, in case, params[:search][:keyword].

http://apidock.com/rails/actionview/helpers/formhelper/form_for

i know you're using simple_form, inherits lot form_for, page still reference


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -