我正在使用RoR构建一个博客.我有index.html.erb页面显示所有帖子的帖子.它显示所有帖子及其所有内容.我想将显示的内容限制为一定数量的字符,然后将"阅读更多"链接转到该个别博客帖子的显示页面.有任何帮助,如何做到这一点?谢谢.
我有一个Posts控制器,我刚安装了Devise,可以快速轻松地添加一些身份验证.在我安装Devise之前,我已经为Posts控制器的'new'动作创建了一些测试.安装Devise后,我的测试失败了,直到我添加了
config.include Devise::TestHelpers, :type => :controller
Run Code Online (Sandbox Code Playgroud)
line到我的spec_helper.rb文件.
我也有这条线
before_filter :authenticate_user!, :except => [:show, :index]
Run Code Online (Sandbox Code Playgroud)
在我的PostsController中.
现在,当我运行我的测试时,除了这两个,它们都通过了:
it "should be successful" do
get :new
response.should be_success
end
it "should have the right title" do
get :new
response.should have_selector('title', :content => @base_title + " | New post")
end
Run Code Online (Sandbox Code Playgroud)
我也在使用工厂女孩.该错误是由before_filter except参数引起的.我需要能够使用工厂用户在rspec中登录用户.如何在Rspec控制器测试中签署Factory用户?如何定义Factory用户?
我在我的工厂里试过这个.rb:
Factory.define :user do |user|
user.name "Test User"
user.email "user@example.com"
user.password "password"
user.password_confirmation "password"
end
Run Code Online (Sandbox Code Playgroud)
但后来我得到了错误:
NoMethodError:
undefined method `password_salt=' for #<User:0x00000103cac958>
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激.谢谢.