在我的交易控制器中,我有行动“topup”和“buy”。两者都在做与“新”行动类似的事情。
在我的“视图”控制器中,我有提交按钮,在这两个视图中,这些按钮都应该导致“创建”动作。
如何设置?
答案 0 :(得分:1)
最简单的方法是在两个地方使用相同的表格。
在每个操作的控制器中,使用任何内容创建新事务 它需要的属性是充值或购买。
def topup
...
@transaction = Transaction.new
end
def purchase
...
@transaction = Transaction.new
end
然后在视图中
<%= form_for @transaction do |form| %>
... needed fields
<% end %>
答案 1 :(得分:1)
您可以自己设置form action url
。只需为这两种表单提供:url
参数。
示例:
<%= form_for :your_resource, url: create_path do |f| %>
...
<%= end %>
您必须在create_path
中添加routes.rb
。
post 'create', as: create # <= This is just an example for your routes!
form helpers
中详细介绍了package com.newgen.servlet.barcode;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BarCodeGenerate extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 7027812863334578584L;
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//System.out.println("anand singh");
response.setContentType("image/jpeg");
OutputStream out1 = response.getOutputStream();
File file1;
//PrintWriter out = response.getWriter();
try{
int width, height;
//String FileName = pInvoiceNumber + "."+ pFileExtn;
//saveFile=new File(FileName);
String pFontFilePath="E:\\Code128.ttf";
String pBarcode=request.getParameter("barcodevalue");
System.out.println(pBarcode);
String format=new String("bmp");
//BufferedImage bi,biFiltered;
width=770;
height=220;
BufferedImage bufimg =new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics graphicsobj = bufimg.createGraphics();
file1=new File(pFontFilePath);
System.out.println(file1.exists());
FileInputStream fin=new FileInputStream(file1);
Font font = Font.createFont(Font.TRUETYPE_FONT,fin);
Font font1 = font.deriveFont(46f);
graphicsobj.setFont(font1);
graphicsobj.setFont(Font.getFont("3 of 9 Barcode")); //3 of 9 Barcode
graphicsobj.setColor(Color.WHITE);
graphicsobj.fillRect(1,1,768,218);
graphicsobj.setColor(Color.BLACK);
((Graphics2D)graphicsobj).drawString("*"+pBarcode+"*",25,170);
ImageIO.write(bufimg,format,out1);
}catch (Exception e){
//out.println(e.getMessage());
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
}
。