So, I’m pretty much a beginner, so I would appreciate some help with this issue.
So, I have link_to helper (yes, I know that button_to is much easer, but for the needs of application it should be link_to), which should POST something in database without rederecting to any pages.
<%= link_to(result_array[k], :controller =>‘tests’, :action => ‘add_key’, :method => :post, :keyword => result_array[k], :position=>k, :remote =>true) + result_array[k+1]%>
This is a classic: rails thinks in this case that :method and :remote are parameters for your controller action, rather than options to apply to the link generation process.
You need something like link_to(result_array[k], {:controller => ‘tests’, …}, :method => :post, :remote => true)
And you also need the rails javascript loaded so that it will add javascript handlers to the links that create and submit a form on the fly
t.
Kinda weird, because I don’t need any forms here and the second trouble that Key exist only like a Model, I didn’t created controller or view for Key because generally I don’t need them.
So I added form:
<% form_for add_key_test_path do |f| %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
and add_key.js.erb to manage autosubmitting:
$(’.source’).click(function(){
$(this).$('.actions').submit()
});
The thing you call submit on is the form, so something along the lines of
$(’.source’).click(function() {
$(‘selector that will find the form’).submit()
})
Fred