Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameter not related to model by form_for on rails?

I'd like to pass parameter not related to model by form_for on rails.I want to pass 'address' data, that is not related to product model, from view to controller. The following is my code, however it returned the next error. Could you tell me how to solve this problem?

Completed 500 Internal Server Error in 11ms (ActiveRecord: 0.1ms) ActionView::Template::Error (wrong number of arguments (1 for 2..5)):

products_controller

class ProductsController < ApplicationController
  ~~~~
  def transfer
    @product = Product.new
  end

  def transfer_done
    my_address = params[:my_address]
    wallet = Wallet.find_by(address:my_address)
    redirect_to root_url
  end
  ~~~~
end

transfer.html.erb

<% provide("transfer") %>
<p>
  <%= form_for @product, :url => {:action => 'transfer_done'} do |f| %>
   <div>
     <%= check_box :my_address %> <---Error occurred here.
   </div>
   <div class="actions">
     <%= f.submit %>
   </div>
  <% end %>
</p>
like image 386
Toshi Avatar asked Nov 16 '25 08:11

Toshi


1 Answers

You may try <%= text_field_tag :my_address %> inside your form

like image 137
Karan Purohit Avatar answered Nov 19 '25 01:11

Karan Purohit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!