假设我有一个文章模型,在文章"新"视图中我有两个按钮,"发布"和"保存草稿".
我的问题是如何知道在控制器中单击了哪个按钮.
我已经有了解决方案,但我认为必须有更好的方法.我目前在视图中使用的是:
<div class="actions">
<%= f.submit "Publish" %>
<%= f.submit "Save Draft", :name => "commit" %>
</div>
Run Code Online (Sandbox Code Playgroud)
所以在控制器中,我可以使用params [:commit]字符串来处理该操作.
def create
@article = Article.new(params[:article])
if params[:commit] == "Publish"
@article.status = 'publish'
// detail omitted
end
@article.save
end
Run Code Online (Sandbox Code Playgroud)
但我认为使用视图相关字符串并不好.你能告诉我另一种方法吗?
更新:由于这些按钮的形式相同,所以它们都会进入"创建"动作,这对我来说没问题.我想要的是在创建操作中处理它,例如给Article模型一个'status'列并保持'public'或'draft'.
<li id="someID">
<div id="div1">Text</div>
<div id="div2">Text x 2</div>
<div id="div3">Text x 3</div>
<span>
<div>
<ul>
<li class="menuItem">Menu Item</li>
</ul>
</div>
</span>
</li>
Run Code Online (Sandbox Code Playgroud)
简而言之,我在点击"menuItem"类时试图找到ID"someID".下面的代码似乎没有削减它.
$('.menuItem').click(function(){alert($(this).closest('li').attr('id'));});
Run Code Online (Sandbox Code Playgroud) 我试图在选择框上进行onchange调用.对于我的应用程序,我使用jquery.js和rails.js来提及UJS.但是生成的代码仍然是Prototype而不是jquery ajax调用.我的代码如下所示:
<%= select_tag :category,
options_for_select(
Category.find(:all,:select=>"name,id").collect{|c| [c.name,c.id]}),
:onchange => remote_function(:url => {:controller => "posts",
:action => "filter_post",
:filter =>"category"},
:with=>"'category_id=' + $('#category').val()") %>
Run Code Online (Sandbox Code Playgroud)
由此生成的代码是:
new Ajax.Request('/posts/filter_posts?filter=category', {asynchronous:true, evalScripts:true,
parameters:'category_id=' + $('#category').val() + '&authenticity_token=' +
encodeURIComponent('CCyYj1wqXtddK6pUV6bAxw0CqZ4lbBxDGQHp13Y/jMY=')})
Run Code Online (Sandbox Code Playgroud) 我正在研究这个程序来获取目录中的所有文件.出于某种原因,我在第16行得到一个NullPointerException.我不知道为什么,因为这是一个似乎与我们的老师在课堂上工作的模板.谢谢.
import java.util.*;
import java.io.*;
public class FindDirectories {
public static void main(String[] args) {
if (args.length == 0) {
args = new String[] { ".." };
}
List<String> nextDir = new ArrayList<String>();
nextDir.add(args[0]); // either the one file, or the directory
try {
while(nextDir.size() > 0) { // size() is num of elements in List
File pathName = new File(nextDir.get(0)); // gets the element at the index of the List
String[] fileNames = pathName.list(); // lists all files in …Run Code Online (Sandbox Code Playgroud) 我是Scala的新手.
Scala最好支持哪种数据库连接?我也在寻找访问数据库的完整示例(验证,连接,查询,提取结果)
我有一个MyTable表,在数据库MyDB中有两列(Value1,Value2),我需要访问它.
我一直在想postgresql,所以一些使用它的例子会很好.
提前致谢.
假设我下载了HTML代码,我可以解析它.如果该网站没有元描述标签,我如何获得该网站的"最佳"描述?
TeamCity有一个非常简单的界面来重新排序构建队列.只需拖放即可.
有没有办法在hudson ci服务器上重新排序或优先构建构建队列?
HII,
我在视图上添加了uipicker.我在不同的文本框上显示的那个视图开始编辑事件.我想从不同文本框编辑事件的不同数据源填充uipicker.所以我想在uipicker视图上刷新或重新加载数据.所以PLZ建议.
postMessage的文档意味着可以进行跨域消息传递.然而:
// When the popup has fully loaded, if not blocked by a popup blocker
Run Code Online (Sandbox Code Playgroud)
这不是一个非常清楚的说明如何实际做到这一点.
想象一下两个网站:
qc-a.nfshost.comqc-b.quadhome.com在父母:
document.addEventListener('message', function(e) {
alert('Parent got (from ' + e.origin + '): ' + e.data);
e.source.postMessage('Round-tripped!', 'http://qc-b.quadhome.com');
}, false);
function go() {
var w = window.open('http://qc-b.quadhome.com', 'test');
/* This doesn't work because same-origin policy prevents knowing when
the opened window is ready. */
w.postMessage('Vain attempt.', 'http://qc-b.quadhome.com');
}
Run Code Online (Sandbox Code Playgroud)
并且,在孩子:
document.addEventListener('message', function(e) {
alert('Child got (from ' + …Run Code Online (Sandbox Code Playgroud) 我想从lucene(Version 3.0.2 for Java)查询中找到匹配的开始和结束位置.看起来我应该能够从Highlighter或FastVectorHighligher获取此信息,但这些类似乎只返回一个文本片段,突出显示相关文本.有没有办法通过荧光笔或ScoreDoc本身获取此信息?
更新:我发现了这个相关的问题: 从Lucene找到搜索命中的位置
但我认为Allasso的答案对我不起作用,因为我的查询是短语,而不是个别条款.
java ×2
jquery ×2
action ×1
cross-domain ×1
database ×1
forms ×1
html ×1
html5 ×1
hudson ×1
iphone ×1
javascript ×1
jdbc ×1
lucene ×1
parsing ×1
postgresql ×1
postmessage ×1
python ×1
reload ×1
scala ×1
string ×1
templates ×1
uipickerview ×1