我在SO上看过ActiveRecord :: DangerousAttributeError和其他类似的线程,但它们没有解决同样的问题.
我正在关注omniauth教程:http://railscasts.com/episodes/235-omniauth-part-1?view = ascicast
我可以使用Twitter通过oauth进行身份验证并返回用户的数据(auth).问题是由于此错误消息,我无法在数据库(sqlite3)中创建/保存它.
ActiveRecord::DangerousAttributeError in AuthenticationsController#create
create is defined by ActiveRecord
Rails.root: /beta/devise-omniauth1
Application Trace | Framework Trace | Full Trace
app/controllers/authentications_controller.rb:15:in `create'
Run Code Online (Sandbox Code Playgroud)
def create
auth = request.env["omniauth.auth"]
current_user.authentications.create(:provider => auth['provider'], :uid => auth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
end
Run Code Online (Sandbox Code Playgroud)
class Authentication < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :authentications
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and …Run Code Online (Sandbox Code Playgroud) message即使我可以看到updateMessage()正在调用,我也无法更新 ExampleView 的var 。这是我的 Playground 代码的简化/复杂 SwiftUI 示例,但它不起作用。将message在调用时变种没有更新updateMessage()。因此,UIText()也不会更新。
为什么@State varmessage没有更新?更新它的正确方法是什么?
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
let coloredLabel = ExampleView()
var body: some View {
VStack {
coloredLabel
.foregroundColor(Color.red)
.padding()
Button(action: {
self.coloredLabel.updateMessage()
}) {
Text("Press me")
}
}
}
}
struct ExampleView: View {
@State private var message: String = "Hello"
var body: some View {
Text(self.message)
}
func updateMessage() {
print("updateMessage ran") // this prints …Run Code Online (Sandbox Code Playgroud) 在最新的 Xcode (10.1) 上,我无法使用编程约束将固定大小的 UIView 添加到我的 UIStackView。我认为这应该很简单,但我不明白额外的约束来自哪里(UIKit 必须打破一些来布局视图)。
问题是我期待 100x100 的蓝色 UIView。现实情况是,蓝色 UIView 是 100% 屏幕宽度和 100% 屏幕高度。
我意识到 UIStackView 使用intrinsicContentSize,但是如何使用编程约束正确设置它?
以下是添加了 UIStackView 和 vanilla UIView 的工作游乐场。
注意:如果我将蓝色 UIView 直接添加到 ViewController 的view,则原点 (0,0) 处的大小为 100x100 是正确的。将其添加到堆栈视图会导致约束冲突。
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
self.view = view
// vertical stack view (full screen)
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
view.addSubview(stackView) …Run Code Online (Sandbox Code Playgroud) ios ×2
swift ×2
activerecord ×1
ios13 ×1
omniauth ×1
railscasts ×1
ruby ×1
swiftui ×1
uikit ×1
uiview ×1