无论如何我可以通过子模型()返回的项目数来订购结果(ASC/ )吗?DESCJobs
@featured_companies = Company.joins(:jobs).group(Job.arel_table[:company_id]).order(Job.arel_table[:company_id].count).limit(10)
Run Code Online (Sandbox Code Playgroud)
例如:我需要打印最高职位的公司
假设我们有一个List<Product>,列表中的每个产品都有很多List<Type>
public class Product{
public int Id {get:set;}
public string Name {get:set;}
public List<Type> Types {get;set;}
}
public class Type{
public int Id {get;set;}
public string Name{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
在创建产品列表后,我需要按类型对它们进行分组,然后找到属于每种类型的所有内容.我想我应该尝试LINQ这个.这是我到目前为止所做的,但似乎不是完成工作的正确方法.可能有人可以帮助我.
var productsList = new List<Product>();
//Adding products and types for each of them
var productTypesList = new Dictionary<int, string>();
foreach (var p in productsList)
{
var pTypes = p.Types;
foreach (var ptype in
pTypes.Where(x=> !productTypesList .ContainsKey(x.Id)))
{
productTypesList.Add(ptype.Id, ptype.Name);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我试着像这样搜索
foreach (var t in …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我现有的rails 3.0.9应用程序中实现switch_user gem.我的应用程序有两个模型,它们是
我已经启用了设计身份验证Users,ActiveAdmin也可以很好地工作AdminUser.现在,从我的Active Admin界面,我想选择帐户并登录这些帐户,就像帐户所有者一样.切换用户工作正常,但问题是如果他们知道网址,任何人都可以直接登录到用户帐户.
HTTP://本地主机:3000/switch_user scope_identifier = USER_1
我只需要允许AdminUser(即,如果有ActiveAdmin会话)访问用户的帐户.
这就是我的/config/initializers/switch_user.rb的样子
SwitchUser.setup do |config|
config.controller_guard = lambda { |current_user, request| current_admin_user.nil?}
config.redirect_path = lambda { |request, params| "/dashboard" }
end
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误
NameError in SwitchUserController#set_current_user
undefined local variable or method `current_admin_user' for main:Object
Run Code Online (Sandbox Code Playgroud)
无论如何我可以访问活动的管理会话吗?
/config/initializers/active_admin.rb的代码
ActiveAdmin.setup do |config|
config.site_title = "MyAppName"
config.authentication_method = :authenticate_admin_user!
config.current_user_method = :current_admin_user
end
Run Code Online (Sandbox Code Playgroud)
顺便说一下我的应用程序控制器我没有创建任何方法authenticate_admin_user,current_admin_user活动管理员没有它们工作正常.
如果有人可以解决一些问题,我会非常感激,因为我对这个问题毫无头绪.基本上我正在尝试使用仅在rails-api gem 之上构建的JSON only rails rest api app来完成设计认证.
我已经实现了如下所述的处理Sessions和Registrations处理.
class ApplicationController < ActionController::API
include ActionController::MimeResponds
end
Run Code Online (Sandbox Code Playgroud)
class SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [:create ]
before_filter :ensure_params_exist
def create
build_resource
resource = User.find_for_database_authentication(:email => params[:user][:email])
return invalid_login_attempt unless resource
if resource.valid_password?(params[:user][:password])
sign_in("user", resource)
render :json=> {:success=>true, :auth_token=>resource.authentication_token, :email=>resource.email}
return
end
invalid_login_attempt
end
def destroy
sign_out(resource_name)
end
protected
def ensure_params_exist
return unless params[:user][:email].blank?
render :json=>{:success=>false, :message=>"missing login email parameter"}, :status=>422
end
def invalid_login_attempt
warden.custom_failure! …Run Code Online (Sandbox Code Playgroud) 我需要在列表中生成一个带有Default值的选择菜单<options>.这就是我需要它的样子.
<select name="menu[parent_id]" id="menu_parent_id">
<option value="0">==None==</option>
<option value="34">TEST</option>
</select>
Run Code Online (Sandbox Code Playgroud)
目前我select在我的表单中使用这个帮助器
<%= f.select(:parent_id, @parent_menus.collect {|p| [ p.name, p.id ] }, {:include_blank => '==None=='})%>
Run Code Online (Sandbox Code Playgroud)
上面的代码产生了这个; (value="")
<select name="menu[parent_id]" id="menu_parent_id">
<option value="">==None==</option>
<option value="34">TEST</option>
</select>
Run Code Online (Sandbox Code Playgroud)
这里有人能告诉我添加value="0"到选项列表的方法吗?
以下nginx配置似乎无法正常工作,并404在访问时返回错误http://example.com/xml_apps/- 但是joomla网站可以从根网址正常工作http://example.com
更新 看起来请求现在发送到codeigniter应用程序,因为404错误来自CI应用程序.
http://example.com/xml_apps/index.php/xmlengine/jmprovince?category=1&count=10
Run Code Online (Sandbox Code Playgroud)
我们是否需要某种配置来添加codeigniter级别?让控制器/动作工作.
server {
listen 80;
root /home/ubuntu/websites/example.com/public_html;
index index.html index.htm index.php;
server_name example.com;
location / {
try_files $uri $uri/ /index.php;
}
location /xml_apps/ {
if ($request_uri ~ "^system.*"){
rewrite ^/xml_apps/(.*)$ /xml_apps/index.php?/$1 last;
}
if (!-e $request_filename){
rewrite ^/xml_apps/(.*)$ /xml_apps/index.php?/$1 last;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD …Run Code Online (Sandbox Code Playgroud) 我想使用"authenticate_ with_ http_ basic"但我无法让它工作.
在我的RoR应用程序中,Authlogic工作正常,我正在使用用户会话.虽然保持这种方法现在我需要使用authenticate_with_http_basic.I有一个iPhone SDK应用程序,现在我需要从我的webapp获取一些产品并显示为列表.所以我假设我需要像这样将请求发送到我的webapp; HTTP://用户名:password@192.168.1.9/products/
所以我的问题是验证这个用户名和密码以及我需要对UserSession控制器做些什么?
devise ×2
activeadmin ×1
activerecord ×1
authlogic ×1
c# ×1
codeigniter ×1
form-helpers ×1
joomla ×1
linq ×1
nginx ×1
rails-api ×1