ruby on rails - Pass a variable from view to controller from form submit -
i trying access variable sent through submit form. not appear present once form submitted.
see hidden field on line: 2
<%= form_for @import, html: { multipart: true } |f| %> <%= f.hidden_field :tree_id, :value => @tree.id %> <%= f.label :new_branch_data %> <div class="help-text">locate file import. (.xls, .xlsx file type)</div> <%= f.file_field :attachment %> <%= f.submit "import", class: "btn btn-primary" %> <% end %>
after hitting submit action called in controller:
def index @tree = tree.find(params[:tree_id]) ... ... end
hangs on @tree = tree.find(params[:tree_id])
, returns
"activerecord::recordnotfound" @ /imports couldn't find tree without id
how can correct @tree variable referenced in form can passed controller?
you can inspect params you're getting guess have tree_id on params[:import] ...
def index @tree = tree.find(params[:import][:tree_id]) ... ... end
Comments
Post a Comment