Note that there are some explanatory texts on larger screens.

plurals
  1. POROR : : submit button should only work for one click and not for second
    primarykey
    data
    text
    <p>Hi i am new to ruby on rails and i am stuck at a place in a form where the submit button should work only once and it should redirect to the same page there after.i am pasting the code snippet which i have used.</p> <pre><code>&lt;%= f.submit "save" ,:class=&gt;"paypal_save_btn_newusernegotiationnew"%&gt; if params[:submit] == "publish" format.html { redirect_to @offerdetail, notice: 'Offerdetail was successfully created.' } format.json { render json: @offerdetail, status: :created, location: @offerdetail } else format.html { render action: "new_offerdetail" } format.json { render json: @offerdetail.errors, status: :unprocessable_entity } end end </code></pre> <ol> <li><p>so far behaviour is that on first click it redirects to the same page and on second click it redirects to default page which is named "show" but i want it to be redirected to the same page.</p></li> <li><p>second problem is on first click it saves data in the right tables which is named "offerdetail"(this is scaffolded) and "fetchfrom" (added model),but on second click data is stored in scaffolded table and not in added model but i am using added model("fetchfrom") in other forms for accessing data.</p></li> </ol> <p>desired behaviour is:</p> <ol> <li>for any number of clicks on submit button it should redirect to same page.</li> <li>data should be saved in both tables.</li> </ol> <p>code for controller is</p> <pre><code>def create #To show purchaser infromation if fb_current_user @msgs="" @purchaser_first_name=fb_current_user.first_name @purchaser_last_name=fb_current_user.last_name @purchaser_email=fb_current_user.email @purchaser_gender=fb_current_user.gender @purchaser_birthdate=fb_current_user.birthday else @msgs="Please login to Facebook" end @offerdetail = Offerdetail.new(params[:offerdetail]) respond_to do |format| if @offerdetail.save # To save current offerid and assigning "0" to usernegotiation_id in Fetchfrom table @fetchfrom = FetchFrom.new @fetchfrom.offer_id=Offerdetail.last.offerid @fetchfrom.usernegotiation_id=0 @fetchfrom.final_purchase_price=Offerdetail.last.price @fetchfrom.total_coupons=Offerdetail.last.cou @fetchfrom.user_id = fb_current_user.id @fetchfrom.save @offer_id = @offerdetail.offerid #To show order_details @offer_value=Offer.find(@offerdetail.offerid).value @offer_purchaseprice =Offer.find(@offerdetail.offerid).purchaseprice @name = Offer.find(@offerdetail.offerid).nameofdeal @retailer_id = RetailersOffer.find_by_offer_id(@offerdetail.offerid).retailer_id @business_name = Retailer.find(@retailer_id ).name if params[:submit] == "publish" format.html { redirect_to new_offerdetail, notice: 'Offerdetail was successfully created.' } format.json { render json: new_offerdetail, status: :created, location: new_offerdetail } else format.html { render action: "new_offerdetail" } format.json { render json: new_offerdetail.errors, status: :unprocessable_entity } end end end end </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload