0

how to pass the date variable into erb puts command

function myDayClickHandler(eventObj){
var date = eventObj.data.calDayDate;
<%puts "asdf",date%>
};

2 Answers 2

1

Javascript and Ruby are something very different. Javascript is client-side, running in the browser. Ruby is run on the server side, separately from client-side code.

Ruby code (<% .. %> parts in your example) is run on the server.

Javascript code (var date = eventObj.data.calDayDate;) is executed in the browser. It's also executed after the Ruby code, when server has processed request and generated result page already.

If you want to know value of date on the server, you'll have to send it from the browser to the server in AJAX request. Any popular Javascript library will help with that.

Sign up to request clarification or add additional context in comments.

2 Comments

I thought he was trying to do the opposite. But I think you're right.
Yeah .. that's not the case @mrlw. The link between the two ends is missing.
0

To pass data to the Rails controller from Javascript, you will need to pass the data back through attaching query parameters in the url.

http://www.google.com?variable1=1&variable2=2

Then in the rails controller you access the variable using

params[:variable1] or params[:variable2]

You can use custom controller actions to perform an activity either using javascript to submit or render, or use traditional HTML. Javascript would be preferred for user experience.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.