我现在只需获取数组的前3个对象并映射它们:
<ul className="ItemSearchList">
{
champions.slice(0,3).map(function(champ){
return (
<li key={champ.id} >
<div className="media">
<div className="media-left">
<a href="#">
<img className="media-object" src={"http://ddragon.leagueoflegends.com/cdn/5.2.1/img/champion/" + champ.key + ".png"} />
</a>
</div>
<div className="media-body" >
<h4 className="media-heading">{champ.name}</h4>
<div>
something
</div>
</div>
</div>
</li>
)
})
}
</ul>
Run Code Online (Sandbox Code Playgroud)
每个champ都有一个level属性(champ.level).
如何将输出排序到champ.level descending切片前3?
我正在尝试显示10个玩家的桌子.我从ajax获取数据并将其作为道具传递给我的孩子.
var CurrentGame = React.createClass({
// get game info
loadGameData: function() {
$.ajax({
url: '/example.json',
dataType: 'json',
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error('#GET Error', status, err.toString());
}.bind(this)
});
},
getInitialState: function(){
return {data: []};
},
componentDidMount: function() {
this.loadGameData();
},
render: function() {
return (
<div className="CurrentGame">
<h1> Current Game Information</h1>
<PlayerList data={this.state.data}/>
</div>
);
}
});
Run Code Online (Sandbox Code Playgroud)
现在我需要一个List Component来渲染玩家:
var PlayerList = React.createClass({
render: function() {
// This prints the correct data
console.log(this.props.data);
return …Run Code Online (Sandbox Code Playgroud) 所以我使用Simple Form for my Rails App,我需要摆脱简单表单附带的每个输入上的标签.
我试过:<%= f.input:email,class:"login-field",label:""%>将标签留空,但这不起作用.
我对rails很新,有人可以解释一下如何实现这个目标吗?
编辑:我正在尝试实现这种格式:
<input type="password" class="login-field" value="" placeholder="Password" id="login-pass" />
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个Listings Controller(设计用户系统)和我刚刚使用的Rails 3
before_filter :authenticate_user!, except: [:index]
Run Code Online (Sandbox Code Playgroud)
在查看特定列表之前检查用户是否已登录.
我的主页(索引)在底部显示了一个视图列表,用户可以看到它们,但是只要他点击一个查看它,他就会被重定向到登录页面.
这就是为什么在我的控制器中我而不是
Listing.new -> current_user.listings.new
Run Code Online (Sandbox Code Playgroud)
在Rails 4中,事情似乎发生了变化,我无法找到正确的方法.
我搜索了一下,发现命令改为
before_action :authenticate_user!, :except => [:index]
Run Code Online (Sandbox Code Playgroud)
访客现在可以查看索引,但如果他点击列表,他不会被重定向到登录页面,而是我收到此错误.
NoMethodError in ListingsController#show
undefined method `listings' for nil:NilClass
# Use callbacks to share common setup or constraints between actions.
def set_listing
@listing = current_user.listings.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
Run Code Online (Sandbox Code Playgroud)
我的房源控制器
class ListingsController < ApplicationController
before_action :set_listing, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, …Run Code Online (Sandbox Code Playgroud) 我有一个Listings controller和用户可以添加说明.如果描述很长,它应该是,我在Heroku中收到此错误:
ActiveRecord::StatementInvalid (PG::StringDataRightTruncation: ERROR:
value too long for type character varying(255)
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
编辑
我发现(John也说)我必须将我的表字符串(有一个限制)更改为:text是无限的.但只是在迁移中更改表似乎不起作用.
我编辑的列表迁移
class CreateListings < ActiveRecord::Migration
def change
create_table :listings do |t|
t.string :title
t.text :description, :limit => nil
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到Heroku麻烦 - >
2013-07-29T09:39:05.069692+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::StringDataRightTruncation: ERROR: value too long for type character v rying(255)
2013-07-29T09:39:05.069870+00:00 app[web.1]:
2013-07-29T09:39:05.069692+00:00 app[web.1]: : INSERT INTO "listings" ("created_at", "description", "image_content_type", "image_file_name", "image_fil _size", "image_updated_at", "price", "title", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, …Run Code Online (Sandbox Code Playgroud) 这是解决方案
所以我正在使用will_paginate/Bootstrap Will Paginate with Endless Scrolling.
为了让分页工作:
1.)在我的控制器中,我更新了我的索引操作
@clips = Clip.order("created_at desc").page(params[:page]).per_page(20)
Run Code Online (Sandbox Code Playgroud)
2.)编辑我的索引视图:
<%= will_paginate @clips%>
Run Code Online (Sandbox Code Playgroud)
DONE
分页工作得很好.
To Add Endless scrolling 我做了与之前的Rails 3 App相同的步骤.
1.)编辑我的clips.js.coffee
jQuery ->
$('#clips-masonry').imagesLoaded ->
$('#clips-masonry').masonry itemSelector: ".clips-masonry" # Thats my Masonry
if $('.pagination').length # Thats for the Endless Scrolling
$(window).scroll ->
url = $('.pagination .next_page a').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
# What to do at the bottom of the page
$('.pagination').text("Fetching …Run Code Online (Sandbox Code Playgroud) javascript ruby-on-rails will-paginate twitter-bootstrap ruby-on-rails-4
我想关掉邮件黑猩猩的确认邮件.我想知道每个地方但没有得到任何网站的任何回复.我如何禁用.没有任何邮件只是用户点击订阅时事通讯并重定向到当前网站.无需邮寄黑猩猩的任何确认邮件.这可能吗.
我正在尝试在我的控制台中测试一个方法,但即使是基本的复数 -
pluralize(1, 'person')
Run Code Online (Sandbox Code Playgroud)
不会工作..
输出:
NoMethodError: undefined method 'pluralize' for main:Object
from (pry):42:in '<main>'
Run Code Online (Sandbox Code Playgroud)
但helper.method(:pluralize)告诉我:Method: ActionView::Base(ActionView::Helpers::TextHelper)#pluralize
我错过了什么?
我正在使用:
我最近设置了我的omniauth-facebook一切正常.现在我想添加omniauth-twitter但不知何故我搞砸了,非常糟糕.
1.)设置我的Omniauth-Facebook我这样做(简而言之):
gem 'omniauth'
gem 'omniauth-facebook'
Run Code Online (Sandbox Code Playgroud)
2.)在我的用户模型中添加了列" provider"和" uid".
3.)接下来,我在config/initializers/devise.rb中声明了提供程序:
require "omniauth-facebook"
config.omniauth :facebook, "App_ID", "App_Secret",
{:scope => 'email,offline_access',
:client_options => {:ssl => {:ca_file => 'lib/assets/cacert.pem'}},
:strategy_class => OmniAuth::Strategies::Facebook}
Run Code Online (Sandbox Code Playgroud)
4.)我编辑了Model User.rb
# Facebook Settings
def self.find_for_facebook_oauth(auth, signed_in_resource = nil)
user = User.where(provider: auth.provider, uid: auth.uid).first
if user.present?
user
else
user = User.create(first_name:auth.extra.raw_info.first_name,
last_name:auth.extra.raw_info.last_name,
facebook_link:auth.extra.raw_info.link,
user_name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20]) …Run Code Online (Sandbox Code Playgroud) 我正在尝试用户模型中strip变量的空格Username.
我正在使用
before_save do
self.username.strip!
end
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用,我错过了什么?