我有一个属于用户的笔记类(即用户可以创建许多笔记).
从笔记控制器剪辑
class NotesController < ApplicationController
before_filter :authenticate_user!
respond_to :html, :xml, :json
# GET /notes
# GET /notes.xml
def index
@notes = Note.includes(:user).order("created_at DESC")
respond_with @notes
end
Run Code Online (Sandbox Code Playgroud)
当我在json结果中请求索引例如/notes.json时,它返回注释但只返回用户对象的user_id.我希望它还包括user.username(并且好奇如何嵌入整个用户对象).
奖金问题:我找不到将列显示为author_id的方法,并将其与用户联系起来.如果这很容易做到,你怎么做?
所以,我已经遵循了这个特定的线程(如何停止在Gallery Widget中滚动?)但我无法让它正常工作.
我创建了一个扩展Gallery的自定义MyGallery类.我在上面的链接中添加了代码...我应该添加<com.example.mygallery
到XML文件中吗?如果是这样,我还要将导入添加到java文件中,还是因为XML文件而不需要?我很困惑.
我想简单地让画廊每次移动一张图像.
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/carlot_background"
>
<com.gallerytest.mygallery
android:id="@+id/thisgallery"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
mygallery.java:
package com.gallerytest;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;
public class mygallery extends Gallery {
public mygallery(Context ctx, AttributeSet attrSet) {
super(ctx);
// TODO Auto-generated constructor stub
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){
return e2.getX() > e1.getX();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PHP和正则表达式检查加号.
这是我到目前为止的代码.
preg_replace('#[^-a-zA-Z0-9_&; ]#', '', $abcd)
Run Code Online (Sandbox Code Playgroud) 我正在研究iphone/ipad的音乐可视化工具,在iOS 3下你可以双击主页按钮并获得iPod控件.使用最新版本4.1-4.2时,按下主页按钮后,这些控件现在显示为灰色.我在http://openradar.appspot.com/8696944上发现了类似的抱怨,尽管没有解决方案.
我将基本声音类别设置为kAudioSessionCategory_PlayAndRecord
,kAudioSessionProperty_OverrideCategoryMixWithOthers
设置为true.(只是为了增加问题的乐趣,我正在使用OpenAl来获得一些音效.)
当应用程序进入后台时,我尝试将类别设置回环境.但要么发生得太晚,要么就是不够.
假设我有一些bash
数组:
A1=(apple trees)
A2=(building blocks)
A3=(color television)
Run Code Online (Sandbox Code Playgroud)
和索引一样J=2
,如何获取数组内容A2
?
我已经和PHP和MySQL徘徊了一段时间,而我所指的电子书建议下载PHP编辑器(IDE)以便更好地编程.
为初学者建议了几个免费的编辑器,这三个都列在这里:
所有这些看起来不错,但如果你能迅速地建议我将不胜感激你的最好的工具这些三或者您使用的任何其他PHP工具.
期待收到你们的回复,谢谢!
我有一张桌子,我想删除<tr>
除第一张桌子以外的所有桌子.我怎样才能做到这一点.?
iPhone报警器在2011年新的一年没有用!http://www.engadget.com/2010/12/31/psa-iphone-alarms-not-working-come-new-years-day-2011/
但只在1月1日.而1月2日.并且只有存在单事件警报时.(重复的警报仍然响起.)
这怎么可能发生?什么样的代码扭曲会导致这种结果?什么荒谬的算法会产生这种不可思议的行为?是否与11月的夏令时相关的警报犯规有关?
我不知道,而且可能性是唯一不会说话的人.
对于这个问题,不要因为你不积极而保持沉默.猜测鼓励.类似错误的故事强烈鼓励.伪代码的额外点.
当我使用MouseClick
树视图控件的事件时,总是选择树中的第一个节点.我该怎么做才能让用户选择当前节点?我正在使用C#.
这是我目前使用的代码:
private void TVRecorder_MouseClick(object sender, MouseEventArgs e)
{
TreeNode selectedNode = TVRecorder.HitTest(e.Location).Node;
if (selectedNode != null)
{
if (selectedNode.SelectedImageKey == "Test_Space")
{
frmRepository rep = new frmRepository();
string ssql = string.Empty;
rep.label1.Text = "Scenario-RepositoryDetails";
rep.LoadAppSettings();
SqlConnection con4 = new SqlConnection();
con4.ConnectionString = "Data Source=" + rep.ScnServer + ";" + "initial catalog=" + rep.ScnDbName + ";" + "User Id=" + rep.ScnUserName + ";" + "Password=" + rep.ScnPwd;
try
{
con4.Open();
}
catch
{
MessageBox.Show("Connection Failed");
}
ssql = …
Run Code Online (Sandbox Code Playgroud)