在我的 android 应用程序中,我有一个聊天 Activity ,我使用 android-chat-starter 中的此代码
问题出在模拟器中,一切正常,我在多种类型的模拟器中进行了测试(api >18,api =18,api <18)>18)>
表情符号 View 显示在键盘上方
这是我用来显示表情符号 View 的代码
private void showEmojiPopup(boolean show) {
showingEmoji = show;
if (show) {
if (emojiView == null) {
if (getActivity() == null) {
return;
}
emojiView = new EmojiView(getActivity());
emojiView.setListener(new EmojiView.Listener() {
public void onBackspace() {
chatEditText1.dispatchKeyEvent(new KeyEvent(0, 67));
}
public void onEmojiSelected(String symbol) {
int i = chatEditText1.getSelectionEnd();
if (i < 0) {
i = 0;
}
try {
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, chatEditText1.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
chatEditText1.setText(chatEditText1.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
chatEditText1.setSelection(j, j);
} catch (Exception e) {
Log.e(Constants.TAG, "Error showing emoji");
}
}
});
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
Log.d(TAG ,Build.VERSION.SDK_INT + " ");
if (Build.VERSION.SDK_INT >= 21) {
windowLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
} else {
windowLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
windowLayoutParams.token = getActivity().getWindow().getDecorView().getWindowToken();
}
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Log.d("emoj",WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + "");
}
final int currentHeight;
if (keyboardHeight <= 0)
keyboardHeight = App.getInstance().getSharedPreferences("emoji", 0).getInt("kbd_height", AndroidUtilities.dp(200));
currentHeight = keyboardHeight;
WindowManager wm = (WindowManager) App.getInstance().getSystemService(Activity.WINDOW_SERVICE);
windowLayoutParams.height = currentHeight;
windowLayoutParams.width = AndroidUtilities.displaySize.x;
try {
if (emojiView.getParent() != null) {
wm.removeViewImmediate(emojiView);
}
} catch (Exception e) {
Log.e(Constants.TAG, e.getMessage());
}
try {
wm.addView(emojiView, windowLayoutParams);
} catch (Exception e) {
Log.e(Constants.TAG, e.getMessage());
return;
}
if (!keyboardVisible) {
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.setPadding(0, 0, 0, currentHeight);
}
return;
}
} else {
removeEmojiWindow();
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.post(new Runnable() {
public void run() {
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.setPadding(0, 0, 0, 0);
}
}
});
}
}
}
@Override
public void onSizeChanged(int height) {
Rect localRect = new Rect();
getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
WindowManager wm = (WindowManager) App.getInstance().getSystemService(Activity.WINDOW_SERVICE);
if (wm == null || wm.getDefaultDisplay() == null) {
return;
}
if (height > AndroidUtilities.dp(50) && keyboardVisible) {
keyboardHeight = height;
App.getInstance().getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight).commit();
}
if (showingEmoji) {
int newHeight = 0;
newHeight = keyboardHeight;
if (windowLayoutParams.width != AndroidUtilities.displaySize.x || windowLayoutParams.height != newHeight) {
windowLayoutParams.width = AndroidUtilities.displaySize.x;
windowLayoutParams.height = newHeight;
wm.updateViewLayout(emojiView, windowLayoutParams);
if (!keyboardVisible) {
sizeNotifierRelativeLayout.post(new Runnable() {
@Override
public void run() {
if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.setPadding(0, 0, 0, windowLayoutParams.height);
sizeNotifierRelativeLayout.requestLayout();
}
}
});
}
}
}
我的 androidmanifest.xml 包含
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<activity
android:name=".ConversationShowActivity"
android:screenOrientation="portrait"
android:label="@string/title_activity_conversation_show"
android:launchMode="singleTask"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.exampel.myapp.MainActivity" />
</activity>
这是我的对话节目 xml
<com.example.myapp.widgets.SizeNotifierRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/chat_layout"
android:layout_height="match_parent"
android:background="@color/white"
xmlns:fontawesometext="http://schemas.android.com/apk/res-auto"
xmlns:bootstrap="http://schemas.android.com/apk/res-auto"
tools:context="com.example.myapp.ConversationShowActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/errorLayout"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:visibility="invisible"
tools:visibilty="invisible"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="Error loading conversation messages, Click here to try again"
android:id="@+id/textView3"
android:textColor="#ffff4314"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/convProgressBar"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/border_bottom"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/conv_header"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:padding="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/conv_avatar"
android:src="@drawable/blank_avatar4"
android:scaleType="fitXY"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aboudi"
android:id="@+id/conv_user_name"
android:textColor="#000000"
android:textSize="18sp"
android:layout_alignTop="@+id/conv_avatar"
android:layout_alignLeft="@+id/conv_online"
android:layout_alignStart="@+id/conv_online"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="conv_online"
android:id="@+id/conv_online"
android:layout_below="@+id/conv_user_name"
android:layout_toRightOf="@+id/conv_avatar"
android:layout_toEndOf="@+id/conv_avatar"
android:layout_marginTop="5dp"/>
<LinearLayout
android:id="@+id/profileFavBtn"
android:layout_width="30dp"
android:background="@drawable/heart_bg"
android:layout_height="30dp"
android:gravity="center"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_alignParentRight="false"
android:layout_toLeftOf="@+id/profilegiftBtn"
android:layout_centerVertical="true">
<com.beardedhen.androidbootstrap.FontAwesomeText
android:id="@+id/profileFavText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fontawesometext:fa_icon="fa-heart-o"
android:textColor="#B94309"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/profilegiftBtn"
android:layout_width="30dp"
android:background="@drawable/accept_btn_bg"
android:layout_height="30dp"
android:gravity="center"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_alignParentRight="false"
android:layout_toLeftOf="@+id/profileReportBtn"
android:layout_centerVertical="true">
<com.beardedhen.androidbootstrap.FontAwesomeText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fontawesometext:fa_icon="fa-gift"
android:textColor="@color/white"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/profileReportBtn"
android:layout_width="30dp"
android:background="@drawable/report_btn_bg"
android:layout_height="30dp"
android:gravity="center"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_alignParentRight="false"
android:layout_toLeftOf="@+id/profileBlockBtn"
android:layout_centerVertical="true">
<com.beardedhen.androidbootstrap.FontAwesomeText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fontawesometext:fa_icon="fa-info"
android:textColor="@color/white"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/profileBlockBtn"
android:layout_width="30dp"
android:background="@drawable/refuse_btn_bg"
android:layout_height="30dp"
android:gravity="center"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true">
<com.beardedhen.androidbootstrap.FontAwesomeText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fontawesometext:fa_icon="fa-remove"
android:textColor="@color/white"
android:textSize="20sp"
/>
</LinearLayout>
</RelativeLayout>
<ListView
android:id="@+id/chat_list_view"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:divider="@drawable/chat_divider"
android:layout_width="match_parent"
android:scrollbarStyle="outsideOverlay"
android:layout_below="@id/conv_header"
android:layout_above="@+id/bottomlayout"
android:layout_height="match_parent"></ListView>
<LinearLayout
android:id="@+id/bottomlayout"
android:background="@drawable/profile_footer_border_top"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/cant_send_text"
android:layout_width="match_parent"
android:text="You cant contact this member right now"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="false"
android:layout_alignTop="@+id/chat_edit_text1"
android:layout_alignBottom="@+id/chat_edit_text1"
android:background="#ff4409"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="15sp"
android:textStyle="bold"/>
<ImageView android:src="@drawable/ic_msg_panel_smiles" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="8dp" android:layout_marginRight="8dp"
android:layout_width="wrap_content" android:id="@+id/emojiButton" android:layout_alignBottom="@+id/chat_edit_text1" android:layout_marginBottom="8dp"
android:layout_height="wrap_content" />
<EditText
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:id="@+id/chat_edit_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollHorizontally="false"
android:layout_toLeftOf="@+id/enter_chat1"
android:layout_toRightOf="@id/emojiButton"
android:layout_toEndOf="@id/emojiButton"
android:layout_toStartOf="@+id/enter_chat1"
android:hint="Type your message here .."
android:singleLine="false"
android:inputType="textCapSentences"
android:textSize="18sp"
android:paddingLeft="4dp" />
<ImageView android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/enter_chat1"
android:layout_width="wrap_content"
android:layout_marginBottom="8dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/chat_edit_text1"
android:paddingLeft="13dp"
android:paddingStart="13dp"
android:paddingRight="17dp"
android:paddingEnd="17dp"
android:src="@drawable/ic_chat_send" />
</RelativeLayout>
</LinearLayout>
</com.example.myapp.widgets.SizeNotifierRelativeLayout >
这是我的表情 View
public class EmojiView extends LinearLayout {
private ArrayList<EmojiGridAdapter> adapters = new ArrayList<EmojiGridAdapter>();
private int[] icons = {
R.drawable.ic_emoji_recent,
R.drawable.ic_emoji_smile,
R.drawable.ic_emoji_flower,
R.drawable.ic_emoji_bell,
R.drawable.ic_emoji_car,
R.drawable.ic_emoji_symbol };
private Listener listener;
private ViewPager pager;
private FrameLayout recentsWrap;
private ArrayList<GridView> views = new ArrayList<GridView>();
public EmojiView(Context paramContext) {
super(paramContext);
init();
}
public EmojiView(Context paramContext, AttributeSet paramAttributeSet) {
super(paramContext, paramAttributeSet);
init();
}
public EmojiView(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
super(paramContext, paramAttributeSet, paramInt);
init();
}
private void addToRecent(long paramLong) {
if (this.pager.getCurrentItem() == 0) {
return;
}
ArrayList<Long> localArrayList = new ArrayList<Long>();
long[] currentRecent = Emoji.data[0];
boolean was = false;
for (long aCurrentRecent : currentRecent) {
if (paramLong == aCurrentRecent) {
localArrayList.add(0, paramLong);
was = true;
} else {
localArrayList.add(aCurrentRecent);
}
}
if (!was) {
localArrayList.add(0, paramLong);
}
Emoji.data[0] = new long[Math.min(localArrayList.size(), 50)];
for (int q = 0; q < Emoji.data[0].length; q++) {
Emoji.data[0][q] = localArrayList.get(q);
}
adapters.get(0).data = Emoji.data[0];
adapters.get(0).notifyDataSetChanged();
saveRecents();
}
private String convert(long paramLong) {
String str = "";
for (int i = 0; ; i++) {
if (i >= 4) {
return str;
}
int j = (int)(0xFFFF & paramLong >> 16 * (3 - i));
if (j != 0) {
str = str + (char)j;
}
}
}
private void init() {
setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i < Emoji.data.length; i++) {
GridView gridView = new GridView(getContext());
// if (AndroidUtilities.isTablet()) {
// gridView.setColumnWidth(AndroidUtilities.dp(60));
// } else {
gridView.setColumnWidth(AndroidUtilities.dp(45));
// }
gridView.setNumColumns(-1);
views.add(gridView);
EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
gridView.setAdapter(localEmojiGridAdapter);
// AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xff999999);
adapters.add(localEmojiGridAdapter);
}
setBackgroundColor(0xff222222);
pager = new ViewPager(getContext());
pager.setAdapter(new EmojiPagesAdapter());
PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
tabs.setViewPager(pager);
tabs.setShouldExpand(true);
tabs.setIndicatorColor(0xff33b5e5);
tabs.setIndicatorHeight(AndroidUtilities.dp(2.0f));
tabs.setUnderlineHeight(AndroidUtilities.dp(2.0f));
tabs.setUnderlineColor(0x66000000);
tabs.setTabBackground(0);
LinearLayout localLinearLayout = new LinearLayout(getContext());
localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
localLinearLayout.addView(tabs, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
ImageView localImageView = new ImageView(getContext());
localImageView.setImageResource(R.drawable.ic_emoji_backspace);
localImageView.setScaleType(ImageView.ScaleType.CENTER);
localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
localImageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (EmojiView.this.listener != null) {
EmojiView.this.listener.onBackspace();
}
}
});
localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(AndroidUtilities.dp(61), LayoutParams.MATCH_PARENT));
recentsWrap = new FrameLayout(getContext());
recentsWrap.addView(views.get(0));
TextView localTextView = new TextView(getContext());
localTextView.setText(getContext().getString(R.string.NoRecent));
localTextView.setTextSize(18.0f);
localTextView.setTextColor(-7829368);
localTextView.setGravity(17);
recentsWrap.addView(localTextView);
views.get(0).setEmptyView(localTextView);
addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dp(48.0f)));
addView(pager);
loadRecents();
if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
pager.setCurrentItem(1);
}
}
private void saveRecents() {
ArrayList<Long> localArrayList = new ArrayList<Long>();
long[] arrayOfLong = Emoji.data[0];
int i = arrayOfLong.length;
for (int j = 0; ; j++) {
if (j >= i) {
getContext().getSharedPreferences("emoji", 0).edit().putString("recents", TextUtils.join(",", localArrayList)).commit();
return;
}
localArrayList.add(arrayOfLong[j]);
}
}
public void loadRecents() {
String str = getContext().getSharedPreferences("emoji", 0).getString("recents", "");
String[] arrayOfString = null;
if ((str != null) && (str.length() > 0)) {
arrayOfString = str.split(",");
Emoji.data[0] = new long[arrayOfString.length];
}
if (arrayOfString != null) {
for (int i = 0; i < arrayOfString.length; i++) {
Emoji.data[0][i] = Long.parseLong(arrayOfString[i]);
}
adapters.get(0).data = Emoji.data[0];
adapters.get(0).notifyDataSetChanged();
}
}
public void onMeasure(int paramInt1, int paramInt2) {
super.onMeasure(View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(paramInt1), MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(paramInt2), MeasureSpec.EXACTLY));
}
public void setListener(Listener paramListener) {
this.listener = paramListener;
}
public void invalidateViews() {
for (GridView gridView : views) {
if (gridView != null) {
gridView.invalidateViews();
}
}
}
private class EmojiGridAdapter extends BaseAdapter {
long[] data;
public EmojiGridAdapter(long[] arg2) {
this.data = arg2;
}
public int getCount() {
return data.length;
}
public Object getItem(int i) {
return null;
}
public long getItemId(int i) {
return data[i];
}
public View getView(int i, View view, ViewGroup paramViewGroup) {
ImageView imageView = (ImageView)view;
if (imageView == null) {
imageView = new ImageView(EmojiView.this.getContext()) {
public void onMeasure(int paramAnonymousInt1, int paramAnonymousInt2) {
setMeasuredDimension(View.MeasureSpec.getSize(paramAnonymousInt1), View.MeasureSpec.getSize(paramAnonymousInt1));
}
};
imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (EmojiView.this.listener != null) {
EmojiView.this.listener.onEmojiSelected(EmojiView.this.convert((Long)view.getTag()));
}
EmojiView.this.addToRecent((Long)view.getTag());
}
});
imageView.setBackgroundResource(R.drawable.list_selector);
imageView.setScaleType(ImageView.ScaleType.CENTER);
}
imageView.setImageDrawable(Emoji.getEmojiBigDrawable(data[i]));
imageView.setTag(data[i]);
return imageView;
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
if (observer != null) {
super.unregisterDataSetObserver(observer);
}
}
}
private class EmojiPagesAdapter extends PagerAdapter implements PagerSlidingTabStrip.IconTabProvider {
public void destroyItem(ViewGroup paramViewGroup, int paramInt, Object paramObject) {
View localObject;
if (paramInt == 0) {
localObject = recentsWrap;
} else {
localObject = views.get(paramInt);
}
paramViewGroup.removeView(localObject);
}
public int getCount() {
return views.size();
}
public int getPageIconResId(int paramInt) {
return icons[paramInt];
}
public Object instantiateItem(ViewGroup paramViewGroup, int paramInt) {
View localObject;
if (paramInt == 0) {
localObject = recentsWrap;
} else {
localObject = views.get(paramInt);
}
paramViewGroup.addView(localObject);
return localObject;
}
public boolean isViewFromObject(View paramView, Object paramObject) {
return paramView == paramObject;
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
if (observer != null) {
super.unregisterDataSetObserver(observer);
}
}
}
public static abstract interface Listener {
public abstract void onBackspace();
public abstract void onEmojiSelected(String paramString);
}
}
当键盘可见时会出现问题,但如果它不可见,则表情符号 View 可以正常工作
最佳答案
不幸的是,对于 Android 5.0(不知道之后)没有办法获得键盘高度。所以你不能使用这个值来定位你的 View 。
但是,您可以使用 softKeyboard 重新布局来做您想做的事情,通过使用值为“resize”的 softKeyboard(在 Activity list 中)将使您的根布局 View 调整为剩余屏幕空间的大小.通过将 View 定位在底部,将使其正好位于键盘顶部。
PS:另外,你的 Root View 需要它的高度值是 match_parent 而不是其他任何东西(或者你需要以其他方式处理)
也许您的意思是您想要替换键盘位置而不是在“顶部”(NORTH?),在这种情况下,您应该使用扩展 View 的 CustomView 而不是使用打开键盘的 EditText你
关于java - 在键盘android上添加 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33137248/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我正在尝试在Ruby中制作一个cli应用程序,它接受一个给定的数组,然后将其显示为一个列表,我可以使用箭头键浏览它。我觉得我已经在Ruby中看到一个库已经这样做了,但我记不起它的名字了。我正在尝试对soundcloud2000中的代码进行逆向工程做类似的事情,但他的代码与SoundcloudAPI的使用紧密耦合。我知道cursesgem,我正在考虑更抽象的东西。广告有没有人见过可以做到这一点的库或一些概念证明的Ruby代码可以做到这一点? 最佳答案 我不知道这是否是您正在寻找的,但也许您可以使用我的想法。由于我没有关于您要完成的工作
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www