将javascript值转换为ruby值
我正在尝试在我的RubyonRails站点中使用AvarieAPI。我很难在onSave函数中找到Aviary创建的URL。我不知道如何用ruby访问它。你有什么想法吗? 我希望ruby中的变量是newURL将javascript值转换为ruby值,javascript,ruby-on-rails,aviary,Javascript,Ruby On Rails,Aviary,我正在尝试在我的RubyonRails站点中使用AvarieAPI。我很难在onSave函数中找到Aviary创建的URL。我不知道如何用ruby访问它。你有什么想法吗? 我希望ruby中的变量是newURL <% if @photo.image? %> <!-- Load widget code --> <script language="JavaScript" type="text/javascript" src="https://dme0ih
<% if @photo.image? %>
<!-- Load widget code -->
<script language="JavaScript" type="text/javascript" src="https://dme0ih8comzn4.cloudfront.net/js/feather.js"></script>
<!-- Instantiate the widget -->
<script type="text/javascript">
var featherEditor = new Aviary.Feather({
apiKey: ' f20374413e3ff5a8',
apiVersion: 2,
theme: 'light',
tools: 'all',
appendTo: '',
fileFormat: 'jpg',
onSave: function(imageID, newURL) {
var img = document.getElementById(imageID);
img.src = newURL;
},
});
function launchEditor(id, src) {
featherEditor.launch({
image: id,
url: src
});
return false;
}
</script>
<!-- Add an edit button, passing the HTML id of the image and the public URL to the image -->
<a href="#" data-refresh="true" onclick="return launchEditor('editimage1',
'<%= @photo.image.url %>');">Edit!</a>
<img id='editimage1' src='<%= @photo.image.url %>' height="352" width="470"/>
<% end %>
var featherEditor=新鸟舍。羽毛({
apiKey:'f20374413e3ff5a8',
版本:2,,
主题:"光",,
工具:“全部”,
附件:“”,
文件格式:“jpg”,
onSave:函数(imageID,newURL){
var img=document.getElementById(imageID);
img.src=newURL;
},
});
函数启动编辑器(id,src){
羽化器({
图片:id,,
网址:src
});
返回false;
}
'height=“352”width=“470”/>
如果您的意思是“将URL发送回表单帖子”,一般策略是将变量填充到隐藏字段的值中,然后引诱用户点击提交按钮,或者为他们点击form.Submit()
。如果您需要发送URL而不刷新页面,则需要使用$.ajax()
。我正在考虑第二种解决方案,但我真的不知道ajax。你认为什么对我来说更容易?你能告诉我如果我选择ajax会怎么样吗?你可以在谷歌上搜索[rails jquery ajax],然后在下面找到一个例子img.src=newURL代码>;很容易让我在这里重复所有这些!