我不确定我的问题措辞是否正确.
我有三个型号:User
,Item
,和UserItem
.
user has_many :user_items
user has_many :items, through :user_items
item has_many :user_items
item has_many :users -> {uniq}, through :user_items
item belongs_to :user
user_item belongs_to :user
user_item belongs_to :item
Run Code Online (Sandbox Code Playgroud)
我需要一种方法来查看用户是否有一个项目if
在我的项目视图中生成语句但是这里是catch,user_items enum status: [ :pending, approved]
.所以我需要看看是否current_user
有某个:pending
项目.
例如,当用户访问item1的视图页面时,我有item_controller的show动作声明@item = Item.find_by_id(params[:id])
.但是,我可以用这个@item
来看看用户是否有这个项目?
我关注此railscast https://www.youtube.com/watch?v=ltoPZEzmtJA但我不使用coffeescript.我试图将coffeescript转换为javascript,但我遇到了问题.
CoffeeScript的
jQuery ->
new AvatarCropper()
class AvatarCropper
constructor: ->
$('#cropbox').Jcrop
aspectRatio: 1
setSelect: [0, 0, 600, 600]
onSelect: @update
onChange: @update
update: (coords) =>
$("#crop_x").val coords.x
$("#crop_y").val coords.y
$("#crop_w").val coords.w
$("#crop_h").val coords.h
Run Code Online (Sandbox Code Playgroud)
js.erb文件
$(document).ready(function() {
$('.crop-image').on('click', function () {
$('#cropbox').Jcrop({
aspectRatio: 1,
setSelect: [0, 0, 100, 100],
onSelect: update,
onChange: update
})
});
update: (function(_this) {
return function(coords) {
$('.user').val(coords.x);
$('.user').val(coords.y);
$('.user').val(coords.w);
return $('.user').val(coords.h);
};
})(this)
});
Run Code Online (Sandbox Code Playgroud)
我不明白为什么他决定上课,并认为改变整个事情会更复杂.我遇到的麻烦是更新功能.我只是将用于更新功能的咖啡脚本插入转换器并使用输出.这导致错误,表示未定义更新.我哪里错了?
另外还有一个问题:他在这里上课的重点是什么?
谢谢!
我想用一个网站的api来使用ruby.说明是发送带有标头的GET请求.这些是来自网站的说明和他们提供的示例php代码.我要计算HMAC哈希并将其包含在apisign
标题下.
$apikey='xxx';
$apisecret='xxx';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
Run Code Online (Sandbox Code Playgroud)
我只是在命令提示符下使用安装在windows上的ruby的.rb文件.我在ruby文件中使用net/http.如何发送带标题的GET请求并打印响应?
如何更改以下代码,以便登录Facebook的用户可以通过设计确认跳过确认?我尝试user.skip_confirmation!
在线下添加,user.email...
但这不起作用.
user.rb:
# Finds or creates user based on omniauth hash from given provider
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.email = auth.info.email
end
end
# Overrides class method 'new_with_session' to persist and validate attributes
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
Run Code Online (Sandbox Code Playgroud)
omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def all
user …
Run Code Online (Sandbox Code Playgroud) 在IE中我遇到了一个问题,我的flex列被拉伸的原因不明.我需要每个弹性项目的图像高度和宽度始终相同,并且响应所以我需要它们100%.我还需要弹性页脚始终与其他页面处于同一级别,无论弹性名称是否超过1行,它都会粘到容器的底部.
.flex-container {
display: flex;
border: 1px solid red;
}
.flex-item-wrapper {
display: flex;
border: 1px solid green;
flex-direction: column;
width: 185px;
}
.link-spanner {
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
}
.flex-header {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: auto;
}
.image-container {
margin-top: 5px;
position: relative;
width: 100%;
}
img {
height: 100%;
width: 100%;
}
.flex-item-name {
max-width: 100%;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
<div class="wrapper">
<div class="flex-container">
<div class="flex-item-wrapper">
<a href='#' …
Run Code Online (Sandbox Code Playgroud)我有
item_params = {
"name" => "",
"description" => "",
"tag_list" => "",
"user_items_attributes" => {"0" => {"user_id" => "8"}},
"created_by" => 8,
"status" => 0
}
Run Code Online (Sandbox Code Playgroud)
我想访问user_id来更改它.
我试过params[:item][:user_items_attributes][0]
但它不起作用.我也试过了params[:item][:user_items_attributes][0][:user_id]
.改变的正确方法是user_id
什么?
我有一个弹性容器,旁边有图片和文本。该容器位于页面中央。当我缩小页面导致文本自动换行时,容器看起来不再居中,因为文本 div 不会缩小到自动换行文本的大小。
自动换行时是否可以缩小文本 div?
请参阅此处的JSFiddle 。
可能很难通过代码片段明白我在说什么,因为您可能无法将页面缩小到足以看到换行的情况。最好看看 jsfiddle。
.container,
.content {
display: flex;
justify-content: center;
}
.picture {
height: 130px;
width: 130px;
background-color: blue;
}
.text {
display: flex;
flex-direction: column;
justify-content: center;
margin-left: 10px;
}
.name {
font-size: 22px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="content">
<div class="picture"></div>
<div class="text">
<div class="name">John Jacobjingleheimer</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以我在设备的可记忆模块上遇到了麻烦.我已正确实现所有设置:我添加:可记住我的用户模型,将remember_created_at添加到users表,并在登录页面上添加:remember_me复选框.
我可以确认,如果用户登录而未选中"记住我"复选框,则表示已创建cookie,现在已过期,并且remember_created_at字段设置为null.如果用户选中该复选框,则时间戳保存在remember_created_at字段中,并且cookie的到期日期设置为默认的2周.
所以我遇到的问题:
如果我没有选中"记住我"复选框并登录,请关闭浏览器,然后返回到我仍然登录的应用程序.如果用户不想记住浏览器关闭时的想法会话被破坏了吗?还是我误解了这个?
为了测试目的,我将:remember_for选项更改为1.minute
.所以我在登录前检查了记住我的框,并验证了cookie的到期日期是否正确,并且时间戳保存在remember_created_at中.然后我关闭了浏览器并等了大约2分钟.然后我再次打开浏览器,我仍然登录.我错过了什么,或者我只是没有正确理解可记忆的模块?
谢谢.
我在模型上使用枚举:
enum status: [:pending, :approved]
我在模型中有一个唯一性验证,如下所示:
validates :item_id, uniqueness: { scope: :user_id, conditions: -> { where(status: :approved) }, message: "You already have this item." }
Run Code Online (Sandbox Code Playgroud)
这不起作用.如果我改变它只会工作:approved
到1
.我很困惑,为什么我不能在这里使用状态名称,当我可以做类似的事情Item.first.update_attributes(status: :approved)
,它工作正常.
在我的整个Web应用程序中,我有各种提交按钮。我可以在用户提交后禁用它们,以防止多个帖子请求和提交到服务器。我还将按钮的文本替换为超棒的字体微调图标。“批准”变为<i class="fa fa-spinner" aria-hidden="true"></i>
。
<a class="btn btn-success" id="approve-button" rel="nofollow" data-method="post" href="/approve?id=40">
Approve
</a>
#approve-button {
height: 34px;
width: 138px;
}
Run Code Online (Sandbox Code Playgroud)
由于文本和字体大小决定了按钮的大小,因此当我用图标替换文本时,按钮会缩小。我看到防止这种情况的唯一方法是手动设置按钮的高度和宽度。但是我必须对所有按钮执行此操作。
有没有一种更简单的方法,我不必手动设置所有按钮的高度和宽度?
css ×3
activerecord ×2
devise ×2
flexbox ×2
html ×2
ruby ×2
associations ×1
coffeescript ×1
css3 ×1
enums ×1
has-many ×1
http ×1
http-headers ×1
javascript ×1
jquery ×1
omniauth ×1
remember-me ×1