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.

<div class = 'source>
<%= link_to(result_array[k], :controller =>'tests',  :action => 'add_key', 
:method => :post, :keyword => result_array[k], :position=>k, :remote 
=>true) + result_array[k+1]%>
</div>


add_key method in tests_controller.rb:

  def add_key
   @test=Test.find(params[:id])
   @[email protected]
   @key.keyword = params[:keyword]
   @key.position = params[:position]
   @key.save
   respond_to do |format|
     format.js
  end
  end


But despite I added :method=>:post option in server log I still see server 
"GET" request.

After an hour of hard googling I found out, that without form submitting 
link_to won't create a "POST" request.

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()
});


But this doensn't work. I spent a 2-3 hours trying to get this finally 
done, but can't find mistake or wrong point. Any advice or help would be 
really appreciated.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/V5qoqaip0cYJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to