first of all, im still learning Ruby on rails, currently im working on rails 4.2.6.
I have a problem with my code, i have a modal where i want to show the information dynamically with ajax (Calling a method in a controller and showing the information on the modal without closing it) but i have a problem, i cant call any function on the modal.
.col-xs-7
%h5="#{period.name}"
.col-xs-5
%form
.input-group
%input.form-control{type: "text", placeholder: "#{t('reports.periods')}"}/
.input-group-btn
%button.btn.transparent-button.dropdown-toggle{"data-toggle" => |
"dropdown", |
type: "button"} |
= svg_icon('icon-arrow-down')
%ul.dropdown-menu.pull-right
- @batch_id.periods.each do |period|
%li
= link_to period.name, '#', :onclick => "myFunction", id: "#{period.id}_id", value: period.id
.row.actions-container
.col-xs-12
%h4="#{@student_id.name}"
%hr
.row.actions-container
.col-xs-12
%form
= label_tag t('batches.observations')
%br
= text_area_tag 'rejection_comments', @comment.try(:comment) , class: 'form-control', :rows => 10, :cols => 30
- content_for(:page_javascript) do
:coffeescript
myFunction = ->
alert 'hello world'
return
Right now im trying only to call the function 'MyFunction' after i select a period but it throws an error:
myFunction is not defined
But if i do this:
- @batch_id.periods.each do |period|
%li
= link_to period.name, '#', :onclick => "alert('hello')", id: "#{period.id}_id", value: period.id
It works...
Can someone tell me what im doing wrong? I want to do the ajax thing as soon as possible.
Ps: The comment part on the text area is the info i want to get from the controller dynamically. Thanks!