在我的Ruby应用程序中,我使用'devise'gem进行身份验证,但我想自定义视图,在自定义每个视图后生成设计视图并将它们作为部分保存在devise文件夹中,因为我想将它们渲染到另一种观点.
所以我的问题是,new/sessions工作正常,但是当我尝试注册时,表单发布似乎存在问题.请在此处查看登录表单
我在设计文档中阅读了很多关于如何自定义布局的内容,但是我对如何实现使表单渲染在devise views文件夹之外工作感到困惑.
我试图在PHP中将数组显示为HTML表,但是存在问题.我在堆栈溢出中找到了几个例子,但它们对我的情况不起作用.
控制器:
<?php include('inc/db_connect.php');?>
<?php
try
{
$sql = "SELECT id GroupName, VideoTITLE, ByArtist FROM videoclip";
$result = $pdo->query($sql);
}
catch(PDOException $e)
{
$error = 'unable to fetch data: '.$e->getMessage();
include'error.html.php';
exit();
}
$URLS = array();
while ($row = $result->fetch())
{
$URLS[] = array('id' => $row['id'], 'GroupName' => $row['GroupName'], 'VideoTITLE' => $row['VideoTITLE'], 'ByArtist'=> $row['ByArtist'] );
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div id="table_admin" class="span7">
<h3>Videoclip List</h3>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Song name</th>
<th>Group name </th>
<th>Artist </th>
</tr>
</thead>
<?php foreach ($URLS …Run Code Online (Sandbox Code Playgroud) 新手在这里,我在应用程序中设置omniauth-facebook,每件事情都运行正常,我唯一的问题是我想在身份验证后重定向到另一个页面,但我无法弄明白.我的第一个解决方案是添加一个路由以匹配auth/facebook/callback到"sessions#new"它不起作用.我尝试的另一件事是在控制器中添加重定向,也不工作,重定向到特定页面的适当的是什么?
调节器
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
sign_in_and_redirect , :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "sign in successfuly") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
Run Code Online (Sandbox Code Playgroud)
路线
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助 .
我遇到了编码挑战:检查给定的正数组是否为幂2,1否则返回0.前
A=[2,3,4]输出: A=[1,0,1]
输入: A =[1048,2048,1048576]
A=[1,1,1]我想出了这个功能.
def checkPw (arr)
arr.map{|a| a != 0 && (a%2==0)?1 :0 }
end
Run Code Online (Sandbox Code Playgroud)
这个函数通过了提供的测试,但我不确定它是否是干净的方法.我想知道是否有更明确的方法来检查数组元素的功能.