Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using submit_tag to declare format

I'm writing a rails app where users generate markers on a google map and then have the option to download them as .kml files. Thing is, I'm adding a feature to change the map to where they can see when they added specific markers to the map, with intervals. I want to use the same form as I did to previously download the .kml files but also add an extra submit button that will not do anything but run some controller logic. I originally had:

<%= form_tag customMapGenerate_path(@device, :format => 'kml'),  :method => :get do %>

for my form_tag

How can I modify my two submit links:

<%= submit_tag 'Download KML' %>
<%= submit_tag 'Display on map' %>

to render KML and then not render anything (and stay on page) for both of the conditions below:

if(params[:commit] == "Download KML")
  respond_to do |format|
    format.kml
  end
  return
elsif(params[:commit] == "Display on map")
  //simple ruby code
  return
end
like image 708
dannymc129 Avatar asked Sep 19 '25 00:09

dannymc129


1 Answers

You can use button_tag

Remove the format from the form_tag and it should give you something like this

<%= form_tag customMapGenerate_path(@device),  :method => :get do %>
 // your form here
 <%= button_tag 'Download KML', value: 'kml', name: 'format' %>
 <%= button_tag 'Display on map', value: 'html', name: 'format' %>
<% end %>

Then in you controller, you simply use the respond_to do |format| to differenciate between your two types of response.

like image 65
Gryfith Avatar answered Sep 20 '25 15:09

Gryfith