Unknown key(s): counter_cache尝试在我的RoR应用程序中实现计数器缓存列时出现错误.
我在这个问题中实现了模型关联:模型关联问题
这是我的迁移:
class AddVideoVotesCountToVideos < ActiveRecord::Migration
def self.up
add_column :videos, :video_votes_count, :integer, :default => 0
Video.reset_column_information
Video.find(:all).each do |p|
p.update_attributes :videos_votes_count, p.video_votes.length
end
end
def self.down
remove_column :videos, :video_votes_count
end
end
Run Code Online (Sandbox Code Playgroud)
然而,在看了http://media.railscasts.com/videos/023_counter_cache_column.mov后,我想也许我不得不在:counter_cache => true之后进入VideoVote模型belongs_to :video.但是,当我这样做时,我收到错误:
wrong number of arguments (2 for 1)
我究竟做错了什么?
ruby ruby-on-rails associations counter-cache ruby-on-rails-3
例如,当用户向问答网站添加问题时,该问题通常会获得自己的网页,并且该网页是即时创建的.你怎么用PHP做到这一点?谁能指点我任何资源?谢谢.
这是测试:
describe "admin attribute" do
before(:each) do
@user = User.create!(@attr)
end
it "should respond to admin" do
@user.should respond_to(:admin)
end
it "should not be an admin by default" do
@user.should_not be_admin
end
it "should be convertible to an admin" do
@user.toggle!(:admin)
@user.should be_admin
end
end
Run Code Online (Sandbox Code Playgroud)
这是错误:
1) User password encryption admin attribute should respond to admin
Failure/Error: @user = User.create!(@attr)
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken
# ./spec/models/user_spec.rb:128
Run Code Online (Sandbox Code Playgroud)
我认为错误可能在我的数据填充程序代码中的某处:
require 'faker'
namespace :db do
desc "Fill database with …Run Code Online (Sandbox Code Playgroud) 我用jQuery动态地附加一些html,我想直接在另一个元素的顶部插入它.我该怎么做呢?
这是我的application.js文件中的代码:
$(document).ready(function() {
$('a.oembed').embedly({maxWidth:300,'method':'replace'}).bind('embedly-oembed', function(e, oembed){
$("#video_div").append($("<img>", { src: oembed.thumbnail_url, width:200 }));
});
});
Run Code Online (Sandbox Code Playgroud)
图像是动态插入的,我希望它直接在这上面:
<div id="video_div"><%= link_to 'video', @video.video_url, :class => 'oembed' %></div>
Run Code Online (Sandbox Code Playgroud) 如何将两种不同的样式应用于"投票"文本和此RoR代码的数字输出:
<%= pluralize video.vote_sum, 'Vote' %>
Run Code Online (Sandbox Code Playgroud) 我在投票控制员中有这条线:
before_filter :authenticate
Run Code Online (Sandbox Code Playgroud)
因此,当我在注销时投票时,它应该使此过滤器失败.
我的应用程序控制器中的我的身份验证方法如下所示:
def authenticate
logged_in? ? true : access_denied
end
Run Code Online (Sandbox Code Playgroud)
所以它返回access_denied如下所示:
def access_denied
redirect_to login_path, :notice => "You must log in to perform this action." and return false
end
Run Code Online (Sandbox Code Playgroud)
因此,我应该被重定向到我的登录页面,对吧?
我在routes.rb文件中有这个:
match '/login' => "sessions#new", :as => "login"
Run Code Online (Sandbox Code Playgroud)
我有一个new登录表单的视图,我应该在我投票时重定向到我没有登录.create我的投票控制器的方法中也有这个代码:
if @vote.save
respond_to do |format|
format.html { redirect_to @video }
format.js
end
else
respond_to do |format|
format.html
end
end
Run Code Online (Sandbox Code Playgroud)
但是当我投票时,我没有重定向,我在日志中收到此错误消息:
Started GET "/login" for 127.0.0.1 at Thu Mar 24 21:18:08 -0700 2011 …Run Code Online (Sandbox Code Playgroud) 我想确保涵盖我的应用程序的所有安全方面.我知道这可能因应用程序而异,但您应该确保采取哪些一般措施来防止安全漏洞?
我在routes.db文件中有这个代码:
resources :users do
member do
get :following, :followers
end
end
Run Code Online (Sandbox Code Playgroud)
我收到错误:
can't use member outside resource(s) scope (ArgumentError)
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
更新:这是我的routes.db文件的所有代码:
SampleApp::Application.routes.draw do
get "sessions/new"
resources :users
member do
get :following, :followers
end
resources :sessions, :only => [:new, :create, :destroy]
resources :microposts, :only => [:create, :destroy]
resources :relationships, :only => [:create, :destroy]
match '/signup', :to => 'users#new'
match '/signin', :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to …Run Code Online (Sandbox Code Playgroud) 假设你有一个.click()电话.您可以在该.click()调用中编写什么代码,以便每次单击所选元素时,可以更改两个字符串之间的文本.我假设.toggle()并将.text()在这里发挥作用......
加载视频节目视图时出现此错误:
SyntaxError in Videos#show
Showing /rubyprograms/dreamstill/app/views/comments/new.html.erb where line #1 raised:
compile error
/rubyprograms/dreamstill/app/views/comments/new.html.erb:1: syntax error, unexpected tASSOC, expecting kEND
...deo.comments.new]), :remote => true do |f| @output_buffer.sa...
^
/rubyprograms/dreamstill/app/views/comments/new.html.erb:6: syntax error, unexpected kENSURE, expecting $end
Run Code Online (Sandbox Code Playgroud)
它在我的comments/new.html.erb文件中指向此表单:
<%= simple_form_for([@video, @video.comments.new]), :remote => true do |f| %>
<%= f.association :comment_title, :collection => @video.comment_titles, :label => "Comment Title:", :include_blank => false %>
<%= f.input :body, :label => false, :placeholder => "Post a comment." %>
<%= f.button :submit, :value => "Post" %>
<% end %> …Run Code Online (Sandbox Code Playgroud) ruby ×5
javascript ×2
jquery ×2
append ×1
associations ×1
css ×1
debugging ×1
dynamic ×1
php ×1
positioning ×1
redirect ×1
rspec ×1
security ×1
syntax-error ×1
testing ×1
webpage ×1