在以下情况下,应将哪些响应代码传递给客户端?
我选择了403.我也发现以下我认为可以使用.
维基百科:
412前提条件失败:服务器不满足请求者对请求提出的前提条件之一
如果我应该使用除403以外的代码,建议代码.
我创建了一个Maven项目,我想Maven在项目的构建路径中添加所有依赖项Eclipse.当我在项目的属性对话框中转到Java Build Path> Add Library> Maven Managed Dependency> Next时,它要求我使用"Maven项目设置"来配置Maven依赖项解析.
我的问题是如何在当前构建路径中添加maven依赖项?
我在访问范围时遇到此错误.
这是AR模型
class StatisticVariable < ActiveRecord::Base
attr_accessible :code, :name
has_many :statistic_values
scope :logins, where(code: 'logins').first
scope :unique_logins, where(code: 'unique_logins').first
scope :registrations, where(code: 'registrations').first
end
Run Code Online (Sandbox Code Playgroud)
当我尝试使用StatisticVariable.logins或任何其他范围时,它给出:
NoMethodError: undefined method `default_scoped?'
Run Code Online (Sandbox Code Playgroud)
如果我将范围配置为类方法,那么它可以完美地工作.
def self.registrations
where(code: 'registrations').first
end
Run Code Online (Sandbox Code Playgroud)
请指导我理解并解决这个问题.
我一直在检查belongs_to方法的选项,并在Rails 3.2.7中测试以下行为
如上所述,该:dependent选项表明了这一点
如果设置为:destroy,则在此对象时销毁关联的对象.如果设置为:delete,则删除关联的对象而不调用其destroy方法.
据我所知,如果在以下情况下删除帖子,则应删除作者:
class Post < ActiveRecord::Base
belongs_to :author, :dependent => :delete
end
class Author < ActiveRecord::Base
attr_accessible :name
has_one :post
before_destroy :log_author_removal
private
def log_author_removal
logger.error('Author is getting removed')
end
end
Run Code Online (Sandbox Code Playgroud)
在控制台中:
> Post.first
Post Load (0.4ms) SELECT "posts".* FROM "posts" LIMIT 1
=> #<Post id: 5, title: "Post 5", author_id: 3>
> p.delete
SQL (197.7ms) DELETE FROM "posts" WHERE "posts"."id" = 5
=> #<Post id: 5, title: "Post 5", author_id: 3>
> …Run Code Online (Sandbox Code Playgroud) 我正在玩spring MVC 3.1并测试不同的功能.我想验证来自@ RequestMapping#value doc的以下声明
If you have a single default method (without explicit path mapping), then all requests without a more specific mapped method found will be dispatched to it. If you have multiple such default methods, then the method name will be taken into account for choosing between them
Run Code Online (Sandbox Code Playgroud)
所以我用多个默认处理程序方法创建了以下控制器
@Controller
@RequestMapping("/book")
public class BookController {
@RequestMapping
public @ResponseBody String greet() {
return "Hi Book!";
}
@RequestMapping
public @ResponseBody String meet() {
return "Nice to meet …Run Code Online (Sandbox Code Playgroud) 我需要从jar加载属性文件.jar包含在war文件中.这是结构
ROOT.war
WEB-INF
lib
my.jar
here my.jar has following structure
my.jar
com
test
myservlet.class
WEB-INF
test.property
Run Code Online (Sandbox Code Playgroud)
现在我在我的一个servlet中编写了以下代码,如下所示:
InputStream stream = getServletContext().getResourceAsStream("/WEB-INF/test.properties");
Properties prop = new Properties();
prop.load(stream );
Run Code Online (Sandbox Code Playgroud)
但是上面的代码我得到了流为null.如果我将属性文件放在ROOT.war/WEB-INF中,它可以正常工作.我很清楚,如果getResourceAsStream中的路径以'/'开头,而不是上下文根中的搜索资源.但是如何读取在根应用程序的WEB-INF/lib中再次找到的jar中的资源?
谢谢和问候,阿米特帕特尔
当我尝试创建一个新项目($ rails new first_app)时,它在创建目录结构后出现以下错误.
...
...
create vendor/plugins/.gitkeep
run bundle install
/home/amit/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- openssl (LoadError)
from /home/amit/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/amit/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/https.rb:22:in `<top (required)>'
...
...
Run Code Online (Sandbox Code Playgroud)
这是Ubuntu 10.04上的配置
$ rails -v
Rails 3.2.1
$ rvm -v
rvm 1.10.2 by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.beginrescueend.com/]
$ bundle -v
Bundler version 1.0.21
$ gem -v
1.8.15
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.
运行时cap deploy,它会在部署期间运行所有迁移.我们必须将应用程序指向现有的DB,并且不希望修改现有的DB.
任何人都可以建议我们在部署应用程序时如何跳过迁移步骤?
我在使用Capistrano 3部署Rails 4应用程序时遇到以下错误
INFO [87512eb8] Running /usr/bin/env chmod +x /tmp/magnificent/git-ssh.sh as deploy@104.236.6.180
DEBUG [87512eb8] Command: /usr/bin/env chmod +x /tmp/magnificent/git-ssh.sh
INFO [87512eb8] Finished in 0.444 seconds with exit status 0 (successful).
INFO [1ec94dd1] Running /usr/bin/env git ls-remote --heads git@github.com:BoTreeConsultingTeam/magnificent.git as deploy@104.236.6.180
DEBUG [1ec94dd1] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/magnificent/git-ssh.sh /usr/bin/env git ls-remote --heads git@github.com:BoTreeConsultingTeam/magnificent.git )
DEBUG [1ec94dd1] ERROR: Repository not found.
DEBUG [1ec94dd1] fatal: Could not read from remote repository.
DEBUG [1ec94dd1]
DEBUG [1ec94dd1] Please make sure you have the correct access rights …Run Code Online (Sandbox Code Playgroud) (twitter) Authentication failure! invalid_credentials: OAuth::Unauthorized, 401 Unauthorized成功上线到Twitter后,我收到错误,页面被重定向到登录页面
这是应用程序配置
的routes.rb
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
Run Code Online (Sandbox Code Playgroud)
devise.rb
config.omniauth :twitter, "KEY", "SECRET"
Run Code Online (Sandbox Code Playgroud)
omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
auth = env["omniauth.auth"]
Rails.logger.info("auth is **************** #{auth.to_yaml}")
@user = user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.new
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.twitter_uid"] = auth["uid"]
redirect_to new_user_registration_url
end
end
end
Run Code Online (Sandbox Code Playgroud)
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# …Run Code Online (Sandbox Code Playgroud) activerecord ×2
capistrano3 ×2
deployment ×2
java ×2
devise ×1
eclipse ×1
github ×1
http ×1
installation ×1
jax-rs ×1
maven ×1
named-scope ×1
omniauth ×1
rest ×1
ruby ×1
servlets ×1
spring-3 ×1
spring-mvc ×1
twitter ×1