I have a nested resource, project/:id/keys
and on .../keys/new
I have a form_for
, the behaviour of this form was modified in JS and its suppose to do a POST request on submit.
The POST request is working fine, but the problem is that it redirects me to another page, more exactly the form action which is 'projects/:id/keys' with the error that create template was not found.
def create
word = word_params[:name]
Word.creates_words word, @project
respond_to do |format|
format.html
format.json {render json: word}
end
end
$('#new_word').on "submit", (event) ->
event.preventDefault()
url = $(this).attr('action')
data = $('#word_name').val()
add_words(url, data)
add_words = (url, data_param) ->
$.ajax
type: 'POST'
url: url
data: word: {name: data_param}
dataType: 'JSON'
success: (json) ->
console.log(json)