小编Thi*_*ijs的帖子

在2D数组中搜索... php

我有这个数组:

$ Fruit = array()

$ Fruit [$ species] [$ property] = $ value

Array
(
    [Apple] => Array
        (
            [Green] => 4
            [Spots] => 3
            [Red] => 3
            [Spots] => 2
        )
Run Code Online (Sandbox Code Playgroud)

现在我想搜索第二个数组中是否存在键...

我试过这个:

if (!array_key_exists($property, $Fruit->$species))
Run Code Online (Sandbox Code Playgroud)

但它不起作用......

有人知道如何搜索阵列数组......?

此致,Thijs

php multidimensional-array array-key

2
推荐指数
1
解决办法
1313
查看次数

设计rails将user_id添加到另一个模型

我想将设计中的current_user.id添加到另一个模型中......

问题模型:

    class Question < ActiveRecord::Base
  belongs_to :user
  attr_accessible :content

  validates :content, :presence => true
end
Run Code Online (Sandbox Code Playgroud)

用户模型:

    class User < ActiveRecord::Base
  has_many :questions
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end
Run Code Online (Sandbox Code Playgroud)

我的问题迁移:

class CreateQuestions < ActiveRecord::Migration
  def change
    create_table :questions do |t|
      t.string :content
      t.date :deadline
      t.integer :user_id

      t.timestamps
    end …
Run Code Online (Sandbox Code Playgroud)

activerecord controller params ruby-on-rails-3

2
推荐指数
1
解决办法
2754
查看次数

单击rails 3中的另一个输入字段时,通过js或jQuery添加文本输入字段

我正在rails 3.1中构建嵌套表单而不是按"添加"按钮我想在空输入字段中键入文本时自动添加输入字段(就像在facebook中提出问题并添加轮询选项一样).但是我也想只添加一个字段,如果在字段中输入了字符,如果删除了字符,则还应删除额外字段.

我正在使用rails 3.1,所以jQuery和jquery-rails包含在我的gem中,我还不知道咖啡脚本.

javascript ruby jquery nested-forms ruby-on-rails-3

1
推荐指数
1
解决办法
1489
查看次数

2个渲染模板(来自设计)在一个页面上(rails 3)

我为我的rails应用安装了设备,我可以进入登录页面或注册页面.但我希望他们都在欢迎页面上...

所以我用以下函数创建了一个welcome_page_controller.rb:

    class WelcomePageController < ApplicationController
  def index
    render :template => '/devise/sessions/new'
    render :template => '/devise/registration/new'

  end
end
Run Code Online (Sandbox Code Playgroud)

但是当我进入欢迎页面时,我收到此错误:

NameError in Welcome_page#index

Showing /Users/tboeree/Dropbox/rails_projects/rebasev4/app/views/devise/sessions/new.html.erb where line #5 raised:

undefined local variable or method `resource' for #<#<Class:0x104931c>:0x102749c>
Extracted source (around line #5):

2: <% @header_title = "Login" %>
3: 
4: 
5: <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
6:   <p><%= f.label :email %><br />
7:   <%= f.email_field :email %></p>
8: 
Run Code Online (Sandbox Code Playgroud)

有谁知道这个问题的解决方案?提前致谢!

它是否与缺少资源功能有关?在welcome_page控制器?它可能在设计控制器的某个地方......?

此致,Thijs

controller devise ruby-on-rails-3

1
推荐指数
1
解决办法
2797
查看次数