0

This is probably very easy, but i just cant seem to find a good answer for myself.

I have this simple HTML Form in my ruby on rails.

  <form target="_blank" action="https://api.xxx.xxx/campaign_id=5011?randomtext">
    <label for="campaign_id">ID:</label>
    <input type="text" id="campaign_id" name="campaign_id"><br>
    <input type="submit" value="Submit">
  </form>

Looks like this https://i.sstatic.net/aEBN5.jpg

What i need:

So user can enter a number and when submit is cliked then the number in the (Form action) URL, in this example the "5011" is replaced with the number given by the user.

So the URL is "https://api.xxx.xxx/campaign_id=5011?randomtext"

when a new number is given and submited. lets use 6050.

Then when submit is clicked, URL changes to "https://api.xxx.xxx/campaign_id=6050?randomtext"

2
  • That is not even a valid url? The question-mark should be before the campaign_id. Should it not be https://api.xxx.xxx/random_text?campaign_id=1234 ? If you use the url without the campaign_id the form will then post the campaign_id to your controller. Commented May 27, 2020 at 11:54
  • 1
    Finally found the problem i had in the post below. stackoverflow.com/questions/1116019/… Commented May 28, 2020 at 9:35

1 Answer 1

1

You can create action in your controller with code

Net::HTTP.get(URI.parse("https://api.xxx.xxx/campaign_id=#{params[:campaign_id]}?randomtext"))

(or using HTTP Gem, HTTParty or any other way)

And in your view something like

<%= form_with url: your_path do |form| %>
  <%= form.text_field :campaign_id %>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.