1

Part of the app i'm developing involves a form which has to create a product on the users shopify store and also create a row in my own database for an identical product (with a few extra bits of information).

Where i'm struggling is with the form itself, i can do this with a html based form, but i can't get a single ruby form to do both jobs. A shortened version of my controller create code is as follows;

def create
    @item = Item.new
    @item.item_title = params[:item_title]
    @item.item_profit = params[:item_profit]
    @new_product = ShopifyAPI::Product.new
    @new_product.title = params[:item_title]
    @new_product.save
    @item.save
end

So as you can see i'm using the same params to set values for both the shopify product and the product in my own db. The HTML form looks like this:

<form action="/items/submit" >
  <input type="text" name="item_title">
  <br>
  <input type="text" name="item_profit">
  <br>
  <br>
  <input type="submit"/>
</form>

And it works fine, but how do i convert this into a ruby form that does the same job?

1
  • 1
    This is just a normal form, not two forms in one... Sep 29, 2016 at 14:22

1 Answer 1

1

You can do like this:

form_tag('/items/submit')
  text_field_tag 'item_title'
  tag("br")
  text_field_tag 'item_profit'
  tag("br")
  tag("br")
<%= submit_tag 'Save' %>

Instead of tag("br"), you can directly use < br />.

1
  • Accepting answer. Totally forgot about form_tag and was leaning towards form_for hence why i couldn't figure this out
    – Dan
    Sep 29, 2016 at 14:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.