我需要渲染另一个控制器动作<%= render "controller/index" %>
,我得到这个错误
缺少部分控制器/索引{{formats => [:html],:locale => [:en,:en],:handlers => [:rjs,:rhtml,:rxml,:erb,:builder]} in查看路径"/ path_to/app/views"
如何将另一个控制器操作呈现到视图中但不向客户端发送重定向?我试过了
<%=render :action => "index", :controller=>"controller" %>
Run Code Online (Sandbox Code Playgroud)
但似乎没有用.
我在一些例子中注意到两种版本化api的方法.
其中一个是在网址中使用版本
/api/v1/products
Run Code Online (Sandbox Code Playgroud)
另一种是使用内容类型标头和接受标头来标记发送到服务器的数据的api版本
Content-Type=application/vnd.company.v2+xml
Run Code Online (Sandbox Code Playgroud)
这种方法的优点和缺点是什么?您将使用每种方法的用例是什么?
我有一个 Rails 应用程序,我通过 Mailgun smtp 发送电子邮件
mail(
to: @user.email,
subject: 'Notification From ME',
'X-Mailgun-Variables' => { subscription_id: subscription.id }.to_json
)
Run Code Online (Sandbox Code Playgroud)
标题在谷歌完整电子邮件视图(原始消息)中显示为
X-Mailgun-Variables: {"subscription_id":2}
Run Code Online (Sandbox Code Playgroud)
当我回复电子邮件时,我收到的讲解员的 Webhook 通知在负载中包含变量。
这个标题应该对客户端可见吗?
我应该如何设置变量或将变量发送到 mailgun,以便在触发电子邮件中继 webhook 时可以接收它们?
我有这个代码:
def create
login(params[:email], params[:password])
if current_user
flash[:notice] = "Welcome back #{current_user.email}"
return redirect_to_first_page
else
flash[:notice] = "Email or password is wrong. Try again !"
redirect_to root_url
end
end
Run Code Online (Sandbox Code Playgroud)
登录成功后,将设置闪存并重定向到第一页.这部分正在运作.第二部分未设置闪存通知消息.然后,当显示页面时,不会显示来自闪存的消息.有什么不同我试着拥有
return redirect_to root_url
Run Code Online (Sandbox Code Playgroud)
但没有任何东西仍然没有显示 在我的控制器中,我有一个像flash_notice这样的帮手,它只是返回flash [:notice].这是因为闪存在视图中始终为空,但在控制器中可访问.在视图中我只有一行:
<%= flash_notice %>
Run Code Online (Sandbox Code Playgroud)
我正在使用rails 3.1
我在使用BsonClassMap映射某些类时遇到问题。我有3个这样的课程:
abstract class A {
public string FirstName { get; set; }
}
abstract class B : A{
public string LastName { get; set; }
}
class C : B {
public int Age { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我只希望将类C中可见的属性映射到数据库。
BsonClassMap.RegisterClassMap<C>(map =>
{
map.MapProperty(c => c.FirstName).SetElementName("fn");
map.MapProperty(c => c.LastName).SetElementName("ln");
map.MapProperty(c => c.Age).SetElementName("age");
});
Run Code Online (Sandbox Code Playgroud)
这引发了一个异常,从我设法发现的异常中似乎是因为这些属性不属于C类。我应该如何映射这种结构?
我正在尝试使规范适用于项目。有一个规格设置但没有维护。
我有一个简单的帖子request spec
require 'rails_helper'
RSpec.describe 'Cars API', type: :request do
let(:organization) { Fabricate(:organization, owner: user) }
let(:app) { Fabricate(:app, organization: organization, owner: user) }
let(:user) { Fabricate(:user) }
before do
#login_api(user)
end
describe 'create' do
describe 'car type' do
it 'should create a car of type CarType1' do
expect(Car.count).to eql(0)
id = '123'
post("/api/1/organization/#{id}/cars")
expect(Car.count).to eql(1)
car = Car.first
expect(car.type).to eql(Car::CarType1)
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
我得到
#<NoMethodError: undefined method `call' for #<App:0x007fee64557080>>
Run Code Online (Sandbox Code Playgroud)
我尝试调试该问题,但没有成功。问题发生在线路上post("/api/1/organization/#{id}/cars")。问题可能出在哪里?
我试图通过将新条目推入数组来更新ui但由于某种原因,直到阵列上的下一个操作才更新ui.
function TestCtrl($scope){
$scope.projects = [{name: "project1"}];
$scope.test = function(){ return "batman"; };
$scope.addNew = function(){
$scope.projects.push({name: "project2"});
setTimeout(function(){
$scope.projects.push({name: "project3"});
}, 1000);
};
}
Run Code Online (Sandbox Code Playgroud)
这是一个例子http://jsbin.com/itasis/4/edit
我还没有测试过,但我希望ajax请求的行为存在同样的问题.