嗨,我是ruby on rails的新手,我被困在一个地方,其中提交按钮应该只工作一次,它应该重定向到那里的同一页面。我正在粘贴我用过的代码片段
<%= f.submit "save" ,:class=>"paypal_save_btn_newusernegotiationnew"%>
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
到目前为止,行为是第一次点击它重定向到相同 页面,然后第二次单击它重定向到命名的默认页面 “show”但我希望将其重定向到同一页面。
第二个问题是第一次点击它会将数据保存在右表中 名为“offerdetail”(这是脚手架)和“fetchfrom” (添加模型),但在第二次点击数据存储在scaffolded中 表而不是添加的模型,但我使用的是添加的模型(“fetchfrom”) 以其他形式访问数据。
期望的行为是:
控制器的代码是
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
提前致谢。