能主动联系使用我的当前设计的用户模型?它已经有一个名为的列admin,如果是的话true,我想绕过Active管理员登录/admin.
这可能吗?
目前的路线:
#Active admin
ActiveAdmin.routes(self)
#Devise
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users, :path => "account"
Run Code Online (Sandbox Code Playgroud)
其余的基本上是标准的Devise + Active管理员
如何让f.error_messages在这里工作,或者我应该使用闪光灯?
如果是这样,在sessions_controller中应该覆盖什么?
<h2>Create an account</h2>
<% form_for resource_name, resource, :url => registration_path(resource_name) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :email %><br />
<%= f.text_field :email, :class => :big %>
</p>
<p>
<%= f.label :password %><br />
<%= f.password_field :password, :class => :big %>
</p>
<p>
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, :class => :big %>
</p>
<p><%= f.submit "Create", :class => :submit %></p>
<% end %>
Run Code Online (Sandbox Code Playgroud)
PS.创建帐户的f.error_messages完全正常.
是否有与RestfulAuthentication 的Authenticate方法等效的方法?
@user = User.authenticate(@email, @password)
Run Code Online (Sandbox Code Playgroud)
我有一个自定义控制器用于验证移动请求,其中电子邮件/密码来自网址,如http:// localhost:3000/iphone/auth/frexuz@frexuz.com/mypassword
可以说我有这样的cronjob:
every 1.day, :at => '4:30 am' do
runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end
Run Code Online (Sandbox Code Playgroud)
虽然,我想让'1.day'更具动态性,例如通过管理页面中的表单更改值.
然后它可能看起来像这样:
every Constant.find(2).value, :at => '4:30 am' do
Run Code Online (Sandbox Code Playgroud)
要么
@const = Constant.find(2)
every @const.span, :at => @const.time do
Run Code Online (Sandbox Code Playgroud)
任何人都可以想出如何使这项工作?
显然,原因是我可以使用我网站上数据库中存储的值,就像消息说的那样
<%= "The next update is in less than #{@const.time}" #or something similar %>
Run Code Online (Sandbox Code Playgroud) 为公寓网站建立搜索引擎,我不知道如何索引apartments表格.
查询示例:
...WHERE city_id = 1 AND size > 500 AND rooms = 2...WHERE area_id = 2 AND ad_type = 'agent' AND price BETWEEN 10000 AND 14000...WHERE area_id = 2 OR area_id = 4 AND published_at > '2016-01-01' AND ad_type = 1如您所见,列可能会有很大差异,WHERE子句中的列数最多可为10,甚至可能更多.
编辑:添加了更新操作,以及错误发生在哪一行
模型:
class Match < ActiveRecord::Base
has_and_belongs_to_many :teams
has_many :match_teams
has_many :teams, :through => :match_teams
accepts_nested_attributes_for :match_teams, :allow_destroy => true
end
Run Code Online (Sandbox Code Playgroud)
控制器:
def new
@match = Match.new
@match_teams = 2.times do
@match.match_teams.build
end
respond_to do |format|
format.html # new.html.erb
format.json { render json: @match }
end
end
def update
@match = Match.find(params[:id])
respond_to do |format|
if @match.update_attributes(params[:match])
format.html { redirect_to @match, notice: 'Match was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" } …Run Code Online (Sandbox Code Playgroud) 我想显示一些通过Ajax加载的亚马逊产品.
我用Ajax调用下面的方法,但请求需要几秒钟.
@items = []
@shows.shuffle.first(5).each do |show|
req = AmazonProduct["us"]
req.configure do |c|
c.key = "###"
c.secret = "###"
c.tag = "###"
end
req << { :operation => 'ItemSearch',
:search_index => params[:product_type],
:response_group => %w{ItemAttributes Images},
:keywords => show.name,
:sort => "" }
resp = req.get
@items << resp.find('Item').shuffle.first
end
Run Code Online (Sandbox Code Playgroud)
我已经注意到这个Action阻止了服务器.我已尝试在另一个标签页中打开该网站.在具有Ajax调用的第一个选项卡完成之前,该选项卡不会开始加载.
我怎样才能解决这个问题?
建立:
Ubuntu 10.10
Rails 3.1.1
Ruby 1.9.2
Gem:https://github.com/hakanensari/amazon_product
我有这个css在每个外部链接后放置一个图标:
a[target="_blank"]:after {
background: url("images/external_icon.png") 0 0 no-repeat;
border: 0 none;
content: "";
padding: 0 14px 0 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我要更改为:before,则图标将显示在链接前面.到现在为止还挺好.
但是在我从右到左的网站版本中,在使用时direction: rtl;,图标仍然显示在元素的右侧,而不是"翻转"到另一侧.更改为a :before仍会使图标显示在元素的右侧.
这是一个已知的FF错误吗?还有其他解决方案吗?(在Chrome中正常工作)
我有一个网站,人们可以添加自己喜欢的电视剧.有一个功能可以检查您看过的剧集.
每个被检查的剧集在DB表中创建一个记录(使用user_id,show_id和episode_id).
这个表现在超过600.000行并且增长非常快!
我已设置索引,但我觉得查询此表时的性能越来越差.
我对新解决方案的想法:
所以代替:
user_id | show_id | episode_id
1 ....... 123 ......7675
1 ....... 123 ......7676
1 ....... 123 ......7677
1 ....... 456 ......5678
1 ....... 456 ......5679
1 ....... 456 ......5680
Run Code Online (Sandbox Code Playgroud)
我能做到这一点:
user_id | show_id | episode_ids
1 ....... 123 ......7675,7676,7677
1 ....... 456 ......5678,5679,5680
Run Code Online (Sandbox Code Playgroud)
然后我必须将字符串拆分成一个数组,并使用array.include?(some-id).
这应该可以减轻数据库的负担,但Ruby会有更多更重的数组代码来处理.
我是在正确的轨道上吗?或者任何人都可以想到更好的解决方案?
Sass 3.2中添加了变量参数.
@mixin hello($arguments...) {
property: $arguments;
}
//Usage:
@include hello(1);
@include hello(1, 2, 3);
@include hello(1, 2);
Run Code Online (Sandbox Code Playgroud)
但是,此参数不接受默认值,如此 ($args...: default-value)
现在,我正在使用此代码,但有更好的方法吗?
@mixin transition($values...) {
$values: null !default;
@if $values == null {
$values: all 0.3s ease;
}
-webkit-transition: $values;
-moz-transition: $values;
-ms-transition: $values;
-o-transition: $values;
transition: $values;
}
Run Code Online (Sandbox Code Playgroud) 它有什么办法吗?或者我们应该责怪苹果?
注意:此问题仅在应用程序模式下发生,而不是在常规Safari浏览模式下.它在iOS6中运行良好.
码:
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<style>
body {
color: blue;
}
@media (orientation:landscape) {
body {
color: red;
}
}
</style>
<body>
<h3>this text will go red when in landscape</h3>
<input type="text" />
</body>
Run Code Online (Sandbox Code Playgroud) 我正在尝试安装Ruby 1.9.3以便能够安装Rails 4.0.我的RVM版本是最新的稳定版.我也试过了apt-get -y update.
rvm list known在列表中显示[ruby-] 1.9.3 [-p448]
请指教 :)
rvm install 1.9.3-p448
Searching for binary rubies, this might take some time.
No binary rubies available for: ubuntu/10.10/i386/ruby-1.9.3-p448.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Installing requirements for ubuntu, might require sudo password.
Hit http://ppa.launchpad.net maverick Release.gpg
Ign http://ppa.launchpad.net/txwikinger/php5.2/ubuntu/ maverick/main Translation-en
Ign http://ppa.launchpad.net/txwikinger/php5.2/ubuntu/ maverick/main Translation-en_US
Ign http://extras.ubuntu.com maverick Release.gpg
Ign http://extras.ubuntu.com/ubuntu/ maverick/main Translation-en
Hit http://ppa.launchpad.net maverick …Run Code Online (Sandbox Code Playgroud)