这似乎与我几天前回答的问题非常相似,但解决方案现在还没有奏效.
我正在构建一个rails应用程序,我正在尝试使用button_to在不同的控制器中触发destroy.
我对按钮的代码是
<%= button_to "delete", :controller => :meals,
:action => 'destroy',
:recipe_id => recipe.id,
:method => :post >
当我点击删除按钮时,我得到一个'不匹配饭/ 3',这是当前的meal_id.
膳食控制器中的破坏看起来像这样
def destroy
@meal = Meal.where("current_user.id => ? AND recipe_id => ?", current_user.id, params[:recipe_id]).first
@meal.destroy
respond_to do |format|
format.html { redirect_to :controller => "user" , :action => "show" }
format.xml { head :ok }
end
end
似乎button_to完全忽略了:action并且请求show不存在且不应该存在.
我正在使用phonegap localNotifications插件,该插件指定我可以设置每周发出的通知.
但是,它似乎只有javascript日期对象有.getDay()和没有.setDay().
我有一个json对象,我想要重复一周的日子,
set_days = {"mon":false, "tues":true,"wed":false,"thurs":true...}
你如何在javascript中设置一天?因为它正在设置通知,所以这一天必须在将来,所以我不想得到最近的"周三",而只是下一个"周三".
这是插件的链接,但我认为这不是插件的特定内容.
我正在构建一个相当简单的配方应用程序来学习RoR,我试图通过单击链接而不是通过表单来允许用户保存配方,所以我通过link_to连接user_recipe控制器的'create'功能.
不幸的是,由于某种原因,link_to正在调用索引函数而不是create.
我把link_to写成了
<%= "save this recipe", :action => 'create', :recipe_id => @recipe %>
此链接位于user_recipes/index.html.erb上,并且正在调用同一控制器的"create"功能.如果我包含:controller,它似乎没有什么区别.
控制器看起来像这样
def index
@recipe = params[:recipe_id]
@user_recipes = UserRecipes.all # change to find when more than one user in db
respond_to do |format|
format.html #index.html.erb
format.xml { render :xml => @recipes }
end
end
def create
@user_recipe = UserRecipe.new
@user_recipe.recipe_id = params[:recipe_id]
@user_recipe.user_id = current_user
respond_to do |format|
if @menu_recipe.save
format.html { redirect_to(r, :notice => 'Menu was successfully created.') }
format.xml { render :xml = … 有一天,我怀疑我必须学习hadoop并将所有这些数据传输到非结构化数据库,但我很惊讶地发现性能在如此短的时间内显着降低.
我有一个不到600万行的mysql表.我正在对这个表做一个非常简单的查询,并且相信我已经准备好了所有正确的索引.
查询是
SELECT date, time FROM events WHERE venid='47975' AND date>='2009-07-11' ORDER BY date
解释返回
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE updateshows range date_idx date_idx 7 NULL 648997 Using where
所以我尽可能使用正确的索引,但这个查询需要11秒才能运行.
数据库是MyISAM,phpMyAdmin表示表是1.0GiB.
这里有什么想法?
编辑:date_idx是日期和静脉列的索引.那些应该是两个单独的索引吗?
我有一个多层嵌套表单
User->Tasks->Prerequisites
并以相同的形式
User->Tasks->Location
位置表单工作正常,现在我正在尝试指定当前任务的先决条件.先决条件是存储在:completed_task字段中的task_id.
当我提交表单时,我在输出中收到以下错误
WARNING: Can't mass-assign protected attributes: prerequisite_attributes
对用户中的每个任务发出一个警告.
我已经完成了与此相关的所有其他问题,确保正确引用字段名称:completed_task,
将attr_accessible添加到我的模型中(它已经存在并且我将其扩展).
我不确定我还应该做什么.
我的模特看起来像
class Task < ActiveRecord::Base
attr_accessible :user_id, :date, :description, :location_id
belongs_to :user
has_one :location
accepts_nested_attributes_for :location
has_many :prerequisites
accepts_nested_attributes_for :prerequisites
end
class Prerequisite < ActiveRecord::Base
attr_accessible :completed_task
belongs_to :task
end
表格使用formtastic,我包括表格via
<%= f.semantic_fields_for :prerequisites do |builder3| %>
<%= render 'prerequisite_fields', :f=>builder3 %>
<% end %>
--- _prerequisite_fields.html.erb -----
< div class="nested-fields" >
<%= f. inputs:completed_step %>
</div>
有什么建议?
我试图了解jQuery在搜索DOM元素时如何创建返回对象.我已经浏览了消息来源,但我并不完全确定我理解,并且希望有人在这里能给我一些见解.
从我可以收集的内容中读取源代码,在查询jQuery DOM时,jQuery找到匹配的DOM元素,然后使用元素的索引作为新对象的键,将匹配的DOM元素添加为对象.
if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
for ( match in context ) {
// Properties of context are called as methods if possible
if ( jQuery.isFunction( this[ match ] ) ) {
this[ match ]( context[ match ] );
// ...and otherwise set as attributes
} else {
this.attr( match, context[ match ] );
}
}
}
return this;
Run Code Online (Sandbox Code Playgroud)
返回this,返回包含所有方法的整个jQuery对象.我是否正确到了这一点?
现在,它出现了所有的功能,如css,find,ajax,hide等.在jQuery.fn对象中.
不知何故(我认为这是我没有看到的地方),这些函数被调用,而不是在DOM元素本身,而是通过access.js https://github.com/jquery/jquery/blob/master/ SRC /核心/ access.js
var access = jQuery.access …Run Code Online (Sandbox Code Playgroud) 我希望这在角度上会非常简单.
我有一个翻译和其他用户的列表
[{user: 'a',languages:['french','english','spanish']},
{user: 'b'}]
Run Code Online (Sandbox Code Playgroud)
然后我有一个ng-repeat,我只想显示拥有语言的用户
ng-repeat="translator in users | filter: {languages}"
Run Code Online (Sandbox Code Playgroud)
但不幸的是,我似乎无法弄清楚如何通过属性的存在来过滤.我已经尝试了各种方式
{languages:'!undefined'}
{languages.length > 0}
{languages.length:'!0'}
Run Code Online (Sandbox Code Playgroud)
我不想为此写一个外部过滤器,因为我确信它有可能是有角度的,我只是无法正确使用它.
我试图从我的指令中获取角度的子元素作为对象,所以我有
link: function(scope,elem,attrs){
var resizeBar = elem.querySelector('.resize-bar');
当我输出时elem,我有一个html对象.但是,我得到一个错误`对象[对象对象]没有方法'querySelector'.
我可以使用元素
var resizeBar = elem.children().children()[1];
但是输出为
<div class="resize-bar">Move</div>
Run Code Online (Sandbox Code Playgroud)
这不是我需要的,我需要resize-bar的html对象.
有人知道一个很好的方法来做角度吗?
elem的控制台输出是
: div.favor-layout.favor-layout-sideways accessKey: "" align: "" attributes: NamedNodeMap baseURI: "file:///C:/Users/pete/projects/favor/favor-layout/index.html" childElementCount: 1 childNodes: NodeList[2] children: HTMLCollection[1] classList: DOMTokenList className: "favor-layout favor-layout-sideways" clientHeight: 200 clientLeft: 0 clientTop: 0 clientWidth: 913 contentEditable: "inherit" dataset: DOMStringMap dir: "" draggable: false firstChild: div.favor-layout-container firstElementChild: div.favor-layout-container hidden: false id: "" innerHTML: "? ? This gets wrapped.? ? move??" innerText: "This gets wrapped.?move" isContentEditable: false …
我一直试图清除我的内存缓存,因为我注意到存储在使用时占用了近30%的服务器内存ps -aux.
所以我运行了以下PHP代码.
$memcache = new Memcache;
$memcache->connect("localhost",11211);
$memcache->flush();
print_r($memcache->getStats());
这导致输出
(
[pid] => 4936
[uptime] => 27318915
[time] => 1255318611
[version] => 1.2.2
[pointer_size] => 64
[rusage_user] => 9.659531
[rusage_system] => 49.770433
[curr_items] => 57864
[total_items] => 128246
[bytes] => 1931734247
[curr_connections] => 1
[total_connections] => 128488
[connection_structures] => 17
[cmd_get] => 170288
[cmd_set] => 128246
[get_hits] => 45464
[get_misses] => 124824
[evictions] => 1009
[bytes_read] => 5607431213
[bytes_written] => 1806543589
[limit_maxbytes] => 2147483648 …Run Code Online (Sandbox Code Playgroud) 我准备写一个api,并认为我会找到一些关于要注意的事情的好建议,如何写一个好的api.
我当然做了谷歌搜索,但除了Dustin Diaz http://www.dustindiaz.com/api-writing-tips/之外,我还没有找到好的建议.
在创建API时,您希望您做了哪些不同的事情?是什么造成了最大的不同.
我假设我要使用oauth.
我故意不提供api的详细信息,因为我正在寻找更多一般性建议,这些建议有望对更多人有用.
angularjs ×2
javascript ×2
api ×1
date ×1
filter ×1
indexing ×1
jquery ×1
link-to ×1
memcached ×1
mysql ×1
nested-forms ×1
performance ×1
php ×1
web-services ×1