小编Mr *_*r H的帖子

accepts_nested_attributes_for rails 4未删除

我现在已经阅读和研究了大约3天.这是我的最后一招.

land.rb:

has_many :uploads , :dependent => :destroy
accepts_nested_attributes_for :uploads, :allow_destroy => true,:reject_if => :all_blank
Run Code Online (Sandbox Code Playgroud)

upload.rb

belongs_to :land
Run Code Online (Sandbox Code Playgroud)

_land_form_partial.html.erb

<%= form_for land , :html => {:multipart => true} do |f| %>

    <%= f.fields_for :uploads do |builder| %>
        <div class="land_fields">
            <%= builder.label :filename, "Image" %>
            <%= builder.text_field :filename %>   <br/>
            Delete: <%= builder.check_box :_destroy %>
        </div>
    <% end %>
 #... buttons and other fields
<% end %>
Run Code Online (Sandbox Code Playgroud)

lands_controller.rb

def update
    if @land.update_attributes(land_params)
      flash[:success] = "Land updated"
      redirect_to lands_path
    else
      flash[:alert] = …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-4

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

Xcode中的行高

如何增加Xcode中线条之间的距离?我的意思是在实际的代码中.

即使我在Xcode首选项中更改字体和字体大小,代码行仍然太靠近而且非常烦人.

xcode xcode4

21
推荐指数
3
解决办法
1万
查看次数

广播INSTALL_REFERRER意图问题

我的Android Manifest文件

<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
      <receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
      </receiver>
Run Code Online (Sandbox Code Playgroud)

我没有任何其他接收器.

测试:

 ~/development/sdk/platform-tools $ ./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.myapp.myapplication/com.google.android.gms.analytics.CampaignTrackingService --es  "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
Run Code Online (Sandbox Code Playgroud)

响应:

Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=com.myapp.myapplication/com.google.android.gms.analytics.CampaignTrackingService (has extras) }
Broadcast completed: result=0
Run Code Online (Sandbox Code Playgroud)

现在,当我运行应用程序时,我得到了 I/GAV3(17797): Thread[GAThread,5,main]: No campaign data found.

然后我尝试了自定义接收器:这是我的代码:

<service android:name="com.myapp.myapplication.ReferrerCatcher"/>
<receiver android:name="com.myapp.myapplication.ReferrerCatcher" android:exported="true">
  <intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

我的接收器:

package com.myapp.myapplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.google.analytics.tracking.android.CampaignTrackingReceiver; 


public class ReferrerCatcher extends …
Run Code Online (Sandbox Code Playgroud)

android google-analytics broadcastreceiver android-intent google-play

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

自定义列表视图不响应click事件

正如您猜测一切正常,没有触发点击事件.在我开始之前,我已经阅读了很多有关此事的帖子,但是对于我的生活,我无法弄明白.这是代码.

activity_main.xml(调用列表的主要布局)

<LinearLayout
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

     <ListView
         android:id="@android:id/list"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"

         />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

list_mainsegments_row.xml(自定义行)

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:orientation="horizontal" 
        >

        <ImageView
            android:id="@+id/iconView"
            style="@style/generalPagesLogoStyle"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_margin="@dimen/tendpPadding"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/titleMainSegments"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:layout_weight="0.5"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="@dimen/generalTextSize"
             />

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="center_vertical"
            android:scaleType="fitCenter"
            android:src="@drawable/arrow" />
    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

MyAdapter.java

   public class MyAdapter extends ArrayAdapter<String> {

    public MyAdapter(Context context, int resource, int textViewResourceId,
            String[] strings) {
        super(context, resource, textViewResourceId, strings);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) …
Run Code Online (Sandbox Code Playgroud)

android listview listadapter onitemclicklistener

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

Repo.update_all 之后 Ecto 中的 Updated_at

我需要更新我的Asset表,所以我需要做这样的事情。

from(a in Asset, 
where: a.id == ^asset.id, 
update: [set: [asset_name: "a name"] ]
)
|> Repo.update_all([])
Run Code Online (Sandbox Code Playgroud)

这工作正常,但updated_at没有更新。

从文档中:

请记住,此 update_all 不会更新自动生成的字段,例如 Updated_at 列。

那么这是否意味着我需要将时间传递到查询中?就像是DateTime.utc_now

谢谢

elixir ecto

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

在Angular 4中导入多个模块中的组件

我有一个 SharedModule

import { NgModule } from '@angular/core';
import { ControlMessagesComponent } from './control-messages.component';

@NgModule({
  imports: [
  ],
  declarations: [
    ControlMessagesComponent
  ],
  exports: [
    ControlMessagesComponent,
  ]
})

export class SharedModule {}
Run Code Online (Sandbox Code Playgroud)

然后我导入了2个不同的模块:

import { SharedModule } from './../shared/shared.module';

@NgModule({
  imports: [
      SharedModule
  ],
  declarations: [
  ],
  providers: [
  ]
})

export class OnboardModule {}

import { SharedModule } from '../shared/shared.module';
@NgModule({
  imports: [
    SharedModule
  ],
  declarations: [

  ],
  providers: [

  ]
})

export class AModule {}
Run Code Online (Sandbox Code Playgroud)

这里是 ControlMessagesComponent

import { …
Run Code Online (Sandbox Code Playgroud)

typescript angular-module angular

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

(RuntimeError) 不支持使用 cast/4 强制转换 assoc,请改用 cast_assoc/3

我不明白这个错误,我搜索了很多。没有一个例子显示多重关联?这是代码。

我的访问列表:

defmodule Db.AccessList do
    use Ecto.Schema

    schema "access_lists" do
        belongs_to :user_id, Db.User
        belongs_to :role_id, Db.Role
        belongs_to :asset_id, Db.Asset
        belongs_to :project_id, Db.Project

        timestamps()
    end

    def changeset(model, params \\ %{}) do
            model
            |> Ecto.Changeset.cast(params, [:user_id, :role_id, :asset_id, :project_id])
            |> Ecto.Changeset.validate_required([:user_id, :role_id])
    end
end
Run Code Online (Sandbox Code Playgroud)

测试:

defmodule AccessListTest do
    alias Db.{ AccessList }
    use ExUnit.Case

    @valid_attr %{user_id: 1, role_id: 1, asset_id: 1, project_id: 1 }

    @tag :wip
    test "ACCESSLIST.1 valid attribute" do
        changeset = AccessList.changeset(%AccessList{}, @valid_attr)
        assert changeset.valid?
    end

    @tag :wip
    test "ACCESSLIST.2 …
Run Code Online (Sandbox Code Playgroud)

elixir ecto

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

如何从AngularJS动态表单中删除元素?

请检查这个小提琴:http: //jsfiddle.net/kgXRa/

这是代码(在JSFiddle中实现)

var app = angular.module('myApp', []);

app.controller('MyCtrl', ['$scope', function ($scope) {
    $scope.field = [];
    $scope.value = [];
    $scope.inputCounter = 0;
}]);

app.directive('addInput', ['$compile', function ($compile) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            element.find('button').bind('click', function () {
                var input = angular.element('<div><input type="text" ng-model="field[' + scope.inputCounter + ']"><input type="text" ng-model="value[' + scope.inputCounter + ']"> <a href="javascript:;" ng-click="remove_it(' + scope.inputCounter + ')">remove</a></div> ');

                var compile = $compile(input)(scope);
                element.append(input);
                scope.inputCounter++;
                scope.remove_it = function(scope_counter) {
                   compile.remove(this);
                   scope.inputCounter--; …
Run Code Online (Sandbox Code Playgroud)

forms jquery angularjs dynamicform

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

如何从数组创建哈希

这是我的数组:

sorted_array = [["Friday", "42", 8], ["Friday", "34", 8], ["Friday", "41", 78], ["Friday", "35", 7], ["Friday", "40", 7], ["Friday", "36", 6], ["Friday", "39", 7], ["Friday", "37", 56], ["Friday", "38", 6], ["Monday", "38", 3], ["Monday", "39", 5], ["Monday", "37", 54], ["Monday", "40", 6], ["Monday", "36", 6], ["Monday", "41", 7], ["Monday", "35", 7], ["Monday", "42", 7], ["Monday", "34", 8]]
Run Code Online (Sandbox Code Playgroud)

我需要做:

{ 'Friday' => [ ["42", 8], ["34", 8], ["41", 78], ["35", 7], [ "40", 7], ["36", 6], [ "39", 7], ["37", 56], …
Run Code Online (Sandbox Code Playgroud)

ruby arrays hash

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

在Java中使用WeakReferences

我一直试图WeakReference在我的Android项目中使用,但我从来没有取得任何成功.现在我真的需要它,因为我正在处理旧设备,我必须尽可能地保持内存清洁.

无论如何,我有一个数组,其中包含大约1000个不同字符串列表.我需要加载它,然后在其中找到一个字符串.

这就是我目前使用它的方式:

String[] campaignList = context.getResources().getStringArray(R.array.campaignList);
WeakReference<String[]> weakCampaignList = new WeakReference<String[]>(campaignList);
Run Code Online (Sandbox Code Playgroud)

这是正确的使用方式WeakReference吗?如果是,那么我不明白的是阵列正在水合,String[]然后我把它传递给了WeakReference.那么这是不是意味着我在分配给一个阵列的内存上有2个点?或者我完全误解了这个WeakReference概念?

我在所有资源中发现的一个非常好的资源就是这个:

http://neverfear.org/blog/view/150/Strong_Soft_Weak_and_Phantom_References_Java

编辑:

我的代码没有问题.只需要知道我在性能方面是否正确.

for (int i = 0; i < weakCampaignList.get().length; i++) {
  Log.d(TAG,"weakCampaignList: "+weakCampaignList.get()[i]);
}
Run Code Online (Sandbox Code Playgroud)

我的整个方法

public static String getTheCampaign(String country, Context context) {
        String campaign = "";
        campaign = "annual_subscription_" + country;

        String[] campaignList = context.getResources().getStringArray(
                R.array.campaign_list);

        ArrayList<WeakReference<String>> weakCampaignList = new ArrayList<WeakReference<String>>();
        for (String s : campaignList) {
            weakCampaignList.add(new WeakReference<String>(s));
        }

        if (country.equals("") || …
Run Code Online (Sandbox Code Playgroud)

java performance memory-management weak-references

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