Tag: 设计

PHP中类似Ruby的数组参数实现

我使用PHP编程,而有时我碰巧需要一种方法来将这些“哈希参数”实现到我的PHP函数中(比如说,一个HTML选择帮助器) draw_select :name => :id, :onclick => ‘alert(this.value)’ PHP中的问题是我必须定义一个参数顺序来实现许多可能的属性。 我一直在考虑定义1个字符串参数并使用json_decode(),所以我可以传递这样的参数: draw_select(“‘name’: ‘id’, ‘onclick’: ‘alert(this.value)’ “) 定义如下: function draw_select($string) { // use json_decode here and pass them as variables } 你知道一个更聪明的方法吗?或者你认为在PHP中使用它实际上是否真的有意义? 编辑添加:我正在寻找一种“替代”替代方案,只需将一个signle数组作为参数传递,如函数(array(…))

设计注销路由错误

我在Rails 3.0.3应用程序中使用Devise 1.5.1。 它运作良好,但有一个例外:注销链接给我这个错误: 路由错误 未初始化的常量UsersController 导致这种情况的链接是: :delete) %> 我还没有创建app / controllers / user_controller.rb文件,但是我的理解是在使用Devise时没有必要,对吗? 如果它是相关的,我的routes.rb文件看起来像: Su::Application.routes.draw do get “group/create” devise_for :users resources :users resources :payers resources :payments resources :categories resources :groups match “adduser”, :to => “groups#adduser” root :to => “pages#home” end …和app / models / user.rb看起来像: class User < ActiveRecord::Base # Include default devise modules. […]

添加嵌套属性以设计用户模型

乍一看,这个问题似乎已经得到了回答,但不是我的情况(大部分都与质量分配问题和/或mongoid有关。)即使这里有很多有些相关的问题,我还是找不到答案。 。 所以基本上我在ruby on rails应用程序上使用devise gem进行用户身份validation,我想在用户模型中添加嵌套地址模型。 我也使用simple_form来生成表单视图。 我有一个用户模型: class User true end 这是地址模型: class Address < ActiveRecord::Base belongs_to :country belongs_to :state belongs_to :user attr_accessible :street1, :street2, :country_id, :state_id, :city, :postalCode end 这是用户控制器,我为了添加show动作来显示用户配置文件而进行了覆盖。 class Users::RegistrationsController after_sign_up_path_for(resource) else set_flash_message :notice, :”signed_up_but_#{resource.inactive_message}” if is_navigational_format? expire_session_data_after_sign_in! respond_with resource, :location => after_inactive_sign_up_path_for(resource) end else clean_up_passwords resource respond_with resource end end […]

自定义设计控制器不工作

我有两个模型常驻和用户。 它们都包含roll_number属性,我现在已经在驻留模型中输入了数据,当用户注册它是Devise资源时它检查驻留模型中是否存在相同的roll_number? 然后用户可以注册!! 所以基本上我将属性(roll_number)添加到Devise的用户模型,然后我编辑了注册控制器的Create方法,这里的代码是: class Users::RegistrationsController < Devise::RegistrationsController before_action :configure_sign_up_params, only: [:create] before_action :configure_account_update_params, only: [:update] # GET /resource/sign_up # def new # super # end def create super resident = Resident.find_by(roll_number: params[:roll_number]) if resident.present? @user = resident.create_user(params) if @user.save flash[:info] = "Welcome to messpay" redirect_to root_url else render 'new' end else flash[:danger] = "You […]

Devise&CanCan – CanCan 2.0 API的问题

我想为我的用户模型添加其他属性,并且不希望创建单独的配置文件模型。 我正在尝试使用RESTful操作集中的标准«更新»来更新自定义字段: class UsersController < ApplicationController before_filter :authenticate_user! # … def update @user = User.find(params[:id]) authorize! :update, @user respond_to do |format| if @user.update_attributes(params[:user]) format.html { redirect_to @user, notice: 'User was successfully updated.' } format.json { head :ok } else format.html { render action: "edit" } format.json { render json: @user.errors, status: :unprocessable_entity } end end […]

users_path(user)在使用devise时返回/users.id而不是/ users / id

我发现当我使用users_path(user)它返回/users.id ,其中id是用户的id,但我希望它返回/users/id 。 我的配置routes.rb如下所示。 # config/routes.rb Test::Application.routes.draw do root to: “static_pages#home” resources :users, only: [:index, :show] devise_for :users end

设计omniauth-facebook redirect_uriurl必须绝对

当我尝试将gem “omniauth-facebook”与设计集成时,我的Rails应用程序,我在facebook上收到以下错误: The redirect_uri URL must be absolute 。 以下是我的配置 devise.rb config.omniauth :facebook, “ID”, “SECRET”,callback_url: “/auth/facebook” 我的user.rb模型: class User [:facebook] def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create do |user| user.email = auth.info.email user.password = Devise.friendly_token[0,20] user.name = auth.info.name # assuming the user model has a name user.image = auth.info.image # assuming the user model has an […]

Ruby on Rails:设计 – 首次登录时更改密码

我有一个应用程序,允许用户将项目输入数据库,他们可以在以后搜索它们。 每个用户都有自己的登录,由系统管理员发出。 当用户第一次登录时,我希望通常的主页显示“更改密码”视图,以便用户在使用应用程序之前必须更改密码。 我在User表中设置了一个pass_change布尔列,在创建新用户时该pass_change false 。 此时,当用户第一次登录时,会将其带到更改密码视图,但是当我测试此function时,密码不会更改,并且在我提交新密码后视图保持不变,并且该用户的pass_change不会更改为true 。 索引视图: Database Search What would you like to do? “button”, :method => “get” %> “button”, :method => “get” %> Change your password resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %> New Password: “password” %> Confirm: “password” %> true %> “button” %> […]

嵌套forms与设计

这是我的注册表格: resource_name, :url => registration_path(resource_name)) do |f| %> Artist: “artist_button” %> Listener: “listener_button” %> “new_user_submit” %> 我的用户模型中也有这个: accepts_nested_attributes_for :profile 但是问题是嵌套在表单中的单选按钮甚至没有出现在页面上。 我怎样才能解决这个问题?

在rails设计ldap gem中检查组成员资格,它是否在yaml中?

我应该使用ldap.yml文件来确保使用ldap进行身份validation是否已为其分配了正确的组以允许它们进入? 无论如何我不是AD专业人士,这让我感到困惑……是一个群体和属性。 据我所知。 我们在AD中有一个用户,他们有一个samAccount名称,我可以让它进入应用程序,但它不关心他们的团队是什么。 它是一个专门的应用程序,实际上有一个memberOf属性: HD Admin HD Helper HD Reset Security 应该都被允许进入应用程序,我也(使用apache目录工作室后)已经意识到有许多memberOf条目: 例如Bob可能有两个memberOf条目: memberOf CN=Security,OU=Groups,OU=Accounts,DC=ACN,DC=ad,DC=tdsu,DC=edu memberOf CN=HD Admin, OU=Groups,OU=Accounts,DC=ACN,DC=ad,DC=tdsu,DC=edu 那么我的yaml看起来怎么样才能做到这些呢? authorizations: &AUTHORIZATIONS group_base: OU=Groups,OU=Accounts,DC=ACN,DC=ad,DC=nmsu,DC=edu ## Requires config.ldap_check_group_membership in devise.rb be true # Can have multiple values, must match all to be authorized required_groups: # If only a group name is given, membership will be […]