Rails - Two Forms In One (ShopifyAPI)
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?
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 />.
- → Trigger a click with jQuery using link_to of rails 4
- → Adding html data attribute to simple_forms input
- → How to remove parameters from the root URL if it does I18n
- → passing parameters to rails back end from an ajax call
- → Blocking ?page= in robots.txt
- → react js and rails Updating state on a component with active record relationship
- → State not passed into prop
- → Cannot read property 'modalIsOpen' of undefined
- → Objects not valid issue
- → How to map API params to model
- → Consuming webhooks shopify-api
- → How to add ScriptTag on shopify_api gem?