好吧,我猜这可能是一个非常直截了当的问题。我似乎打破了我的应用程序的一个功能,它显示了提交帖子的人的用户名(在我的情况下是'pin')。
这一切都发生在我将用户名添加到数据库(设计)的时候,因为之前我只显示了电子邮件地址,觉得这不是我想要的。
Tl; dr:= pin.user.username ( app / views / pins / index.html.haml )不显示该用户的用户名提交了这个帖子。但是,它会显示带有 pin.user.email 的电子邮件。
这是我的PinsController(在我的例子中是Pin in the design in devise)
class PinsController < ApplicationController
before_action :find_pin, only: [:show, :edit, :update, :destroy, :upvote, :downvote]
before_action :authenticate_user!, except: [:index, :show]
attr_accessor :username
def index
@pins = Pin.all.order("created_at DESC")
end
def show
end
def new
@pin = current_user.pins.build
end
def create
@pin = current_user.pins.build(pin_params)
if @pin.save
redirect_to @pin, notice: "Fit was successfully created"
else
render 'new'
end
end
def edit
end
def update
if @pin.update(pin_params)
redirect_to @pin, notice: "Fit was successfully updated"
else
render 'edit'
end
end
def destroy
@pin.destroy
redirect_to root_path
end
def upvote
@pin.upvote_by current_user
redirect_to :back
end
private
def pin_params
params.require(:pin).permit(:title, :description, :image)
end
def find_pin
@pin = Pin.find(params[:id])
end
end
这是我的index.html.haml
#pins.transitions-enabled
- @pins.each do |pin|
.box.panel.panel-default
= link_to (image_tag pin.image.url), pin
%h2= link_to pin.title, pin
%p.user
Submitted by
= pin.user.username
我的架构为用户显示了这个
add_index "pins", ["user_id"], name: "index_pins_on_user_id"
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "username"
end
我已经附上了我的git,只是你需要一些具体的细节 https://github.com/thgilartlU/MyFitIdentity
答案 0 :(得分:0)
你的问题不是haml,你试图显示的用户名似乎是空的。你的haml结构看起来很好。
正如您pin_params
中提到的那样username
是不允许的,因此请确保允许并将其保存到数据库中。比你的haml应该工作。
答案 1 :(得分:0)
删除
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
//Call to the algorithm class
RespAlgo myAlgo = new RespAlgo();
@Override
protected void onCreate(Bundle savedInstanceState) {
//Code to initiate the graphs...
}
private final BluetoothGattCallback mGattCallback =
new BluetoothGattCallback() {
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
{
// Here I catch the data from the BLE device
for (int i_bt_nTs = 0; i_bt_nTs < getResources().getInteger(R.integer.bt_nTs); i_bt_nTs++) {
//V2V8, S1, S2, S3
// k = R3/(Rs + R4) = V2V8/(ADCval * LSB / Gain + V2V8/2) - 1
// Rs = R3/k - R4
v2v8_val = v2v8_2_bval * 2 * adc_lsb * vbat_correction;
k = v2v8_val / (characteristic.getIntValue(FORMAT_UINT16, 2 + 6 * i_bt_nTs) * adc_lsb / ina_gain + v2v8_val / 2) - 1;
rs1 = R3 / k - R4;
//run the algorithm. the below should move to parallel task
// Add counter to the algorithm
myAlgo.addTime();
//Add value from the sensor to the algorithm
myAlgo.setValue(rs1);
//Return result to rr1 variable
rr1 = (float)myAlgo.getRR();
// Change the UI with the new value
myRR1.setText(String.valueOf(rr1));
}
}
来自您的attr_accessor :username
def username=(username)
@username = username
end
模型文件,它会混淆ActiveRecord