问题标签 [helpermethods]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
38 浏览

ruby-on-rails - 从 Rails 中的视图执行 ruby​​ 代码

这段代码是从一个视图中执行的,它可以工作:

我想做同样的事情,但http://www.someurl.com作为 javascript 计算的参数传递,就像这样

尝试 1

它不起作用。

尝试 2

并在控制器中

它也不起作用。

这两种情况似乎都对 cookie 有问题。有没有办法使用一些 javascript 从视图中运行 OpenGraph.fetch(parameter) variable

0 投票
2 回答
77 浏览

c# - 检查是否存在来自 MVC C# 中的帮助程序/扩展方法的特定脚本

如果视图中存在某个脚本,是否有办法签入帮助程序/扩展方法?

我的想法是创建一个自定义 TextBoxFor() 方法,一旦当前输入达到 maxLenght,焦点就会移动到下一个输入。

0 投票
1 回答
130 浏览

ruby-on-rails - Only need simple_format when there are is new line \n

I have some strings that contain carriage return (new lines), and using the helper method simple_format works perfect for that.

Unfortunately though, now all strings get the wrapping tag and class defined with simple_format, and that creates unwanted styling for strings that don't contain carriage return.

Is there any way to get the benefits of simple_format only when needed?

0 投票
2 回答
826 浏览

java - 辅助方法中的递归(Java)

我正在练习递归并使用递归辅助方法。在我的辅助方法中,出现一个错误,说明

Tree 类型中的方法 someMethod(K) 不适用于参数 (K, List, int)。

但是,我不想使用该someMethod(K k)方法,因为我正在尝试使用someMethod(K k, List<K> L, int n)辅助方法。如何让 Eclipse “知道”我正在尝试使用其他方法?

到目前为止,这是我所拥有的:


编辑:左右声明:

0 投票
1 回答
262 浏览

ruby-on-rails-4 - How set up and call a rails method in the view to update an attribute of an object

I need some help in figuring out how to set up a helper method and then call in in the view. What i need to do is update a single attribute of a model object.

How I plan to do this is to call a helper method Bid, which will update the attribute by the same increment every time, for example, by one dollar.

Then, I need a way to call this helper method in the view and update the auction attribute current_price and display it in the view. Any ideas on how this could be done? Thanks

0 投票
2 回答
159 浏览

ruby-on-rails - NoMethodError,未定义的方法“出价”

我一直在尝试从我的控制器在 rails 对象上调用辅助方法,但我继续收到此错误。这是我所有的代码。

看法

堆栈跟踪

谁能告诉我我的代码是错误的还是方法不正确?谢谢

编辑请在下面查看我的答案,这是我真正的问题...

0 投票
1 回答
931 浏览

ruby-on-rails - 从视图调用辅助方法时出现“未定义的方法”

我想从这样的辅助方法中获取一个人的性别:

sportists_helper.rb

然后在视图中打印出来: <%= sportists_gender %>,但这给了我undefined method 'gender'错误,这是为什么呢?

0 投票
1 回答
34 浏览

ruby-on-rails - Rails:如何确定辅助方法“指向”的位置

在此页面的开头附近...

http://guides.rubyonrails.org/routing.html

...有一个涉及@patient 的示例(第 1.2 节)。

我想知道如何确定以下线指向的位置:

rake 路由生成的列表与此相关吗?
我如何知道使用了哪个 http 动词?

编辑

我想补充一点,将我指向“rake routes”不会为我解释。我已经多次检查我的路线列表。

我想知道,在上面 URL 的示例中,我如何知道 link_to 线指向的位置。看起来路线列表很重要,但它与 patient_path 线有什么关系?我错过了什么?

0 投票
0 回答
141 浏览

ajax - 为什么控制器操作不发送 json 数据作为响应

我学习 ASP.NET MVC 并且遇到了一些问题。

我在视图中通过 ajax 辅助方法创建了两个链接。他们发送 mailsType 参数和响应 json 数据。这是链接和 AjaxOptions 对象的代码

这是 ajaxoption,在 ajax 助手中使用

我通过javascript函数处理响应

这是控制器中的操作方法代码

当我使用第二个链接时一切正常,但是当我使用第一个链接时,我有内部服务器错误,代码为 500,响应类型为 text/html。我使用此链接返回部分视图,它们以前都可以使用。

我尝试使用自己的 ajax 请求,但结果仍然相同。我不明白出了什么问题。我不明白这个问题是抽象的,但可能是你有同样的问题或知道它为什么会发生。

编辑1

当我从地址栏中的链接写入地址时,出现此错误:System.InvalidOperationException:此流不支持超时。

我尝试在 ajax 请求中设置大超时,但没有帮助。当我发送较少的数据作为响应时,请求成功执行。我认为这与响应发送的数据大小有关。我错了吗?这个错误的原因可能是什么?

我会很高兴你的所有建议。谢谢大家!

0 投票
1 回答
934 浏览

ruby-on-rails - Ruby on rails:整个应用程序的以前的 url 助手

是否有一种简单的方法可以编写一个帮助方法来始终更新会话中先前访问的 url。我尝试了下面的方法,但保存的 url 始终是当前的。我希望能够在我的所有控制器中使用这个帮助器进行重定向。

我在用户控制器的更新方法中使用了它,如下所示,但它总是重定向到同一个打开的 url(有点像刷新被击中)。