vendredi 1 décembre 2017

'create' button by calling update method instead of create

here is my code to create new object via form:

 <%= form_for @ticket, url: new_geradorqrcode_path(@ticket), html: { method: :put } do |t| %>
<p>
    <%= t.label :Descricao %></br>
    <%= t.text_area :descricao, cols: 20, rows: 5 %>

</p>

<p>
    <%= t.label :Tipo %></br>
    <%= t.text_field :tipo %>
</p>


<p>
    <%= t.label :Tamanho %></br>
    <%= t.number_field :tamanho_arquivo %>
</p>


 <p>
    <%= t.label :Cliente %></br>
    <%= t.text_field :cliente %>
</p>

<p>
    <%= t.label :Valor %></br>
    <%= t.number_field :valor %>
</p>

<p>
    <%= t.submit %>
</p>

but when i click in 'create' button, this error appears :

erro

I created both 'update ' and 'create' methods in controller :

def update
    @ticket = Ticket.find(params[:id])
    ticket_params = params.require(:ticket).permit(:descricao,:valor, :cliente, :tamanho_arquivo, :tipo)
    @ticket.update(ticket_params)
    redirect_to url: geradorqrcode_path(@ticket), html: { method: :post }
end

and 'create' method :

def create
    @ticket = Ticket.new(params[:ticket])
    @ticket.save
    redirect_to url: geradorqrcode_path(@ticket), html: {method: :post}
end




Aucun commentaire:

Enregistrer un commentaire