我有一个视图,其中包含以下ruby代码,我想在我的应用程序中创建动态链接:
<% @customer.jobs.each do |job| %>
<%= link_to job.id, job %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这会为job_path抛出一个未定义的方法错误,这是有道理的,因为我的jobs_controller show方法是空的:
def show
end
Run Code Online (Sandbox Code Playgroud)
这是我的路线:
resources :customers do
resources :jobs
end
Run Code Online (Sandbox Code Playgroud)
我的问题是 - 如何在控制器中设置方法以使我的link_to在视图页面上工作?
基本上,我从数据库中提取项目,然后尝试使用数据库项创建指向相应视图的链接.
有任何想法吗?
我尝试Silex Framework,我可能想将参数传递给控制器方法.我有这个,就像在doc中一样:
$app->get('/projet/{projetName}', 'App\Controller\Projet::single')
->bind('single.projet');
Run Code Online (Sandbox Code Playgroud)
如何将'projetName'传递给'single'方法?
我试图将子视图控制器添加到containerViewController
孩子是:
AViewController
BViewController
CViewController
Run Code Online (Sandbox Code Playgroud)
我没有错误但是当我启动应用程序时,我可以刷屏幕,有3个部分刷,但A,B,C视图控制器没有出现..
这是我的代码,任何想法?
import UIKit
class ContainerViewController: UIViewController {
@IBOutlet var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// creat VC
var Avc : AViewController = AViewController ()
var Bvc : BViewController = BViewController ()
var Cvc : CViewController = CViewController ()
// add it to the view hierarchie
self.addChildViewController(Cvc)
self.scrollView.addSubview(Cvc.view)
Cvc.didMoveToParentViewController(self)
self.addChildViewController(Bvc)
self.scrollView.addSubview(Bvc.view)
Bvc.didMoveToParentViewController(self)
self.addChildViewController(Avc)
self.scrollView.addSubview(Avc.view)
Avc.didMoveToParentViewController(self)
// set the frame
var …Run Code Online (Sandbox Code Playgroud) 这应该是一个单行,但我不习惯Spring或SpringBoot,所以我遇到了麻烦.
我正在使用查询参数构建RESTful服务.例如:http://myweatherapi.com:8080/foo?zip=14325&prop=humidity.
我正在尝试一个SpringBoot的模板,在其中我有这个控制器:
@RestController
public class ServiceController {
private static Logger LOG = LoggerFactory.getLogger(ServiceController.class);
@RequestMapping("/foo")
public String foo(@QueryParam("foo") String foo) {
requestContextDataService.addNamedParam("foo", foo);
// how can I access the full URL/query params here?
return "Service is alive!!";
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何访问完整的URL /查询参数?
嗨,我有一个问题,因为索引似乎没有在我的佣金路线正确显示
我已经在我的控制器模块中定义了索引
def index
@user_friendship = current_user.user_friendships.all
end
Run Code Online (Sandbox Code Playgroud)
我还在视图中将其定义为index.html.erb
但我的问题是它现在显示在我的佣金路线中这是我唯一得到的
accept_user_friendships PUT /user_friendships/accept(.:format) user_friendships#accept
user_friendships POST /user_friendships(.:format) user_friendships#create
new_user_friendships GET /user_friendships/new(.:format) user_friendships#new
edit_user_friendships GET /user_friendships/edit(.:format) user_friendships#edit
GET /user_friendships(.:format) user_friendships#show
PATCH /user_friendships(.:format) user_friendships#update
PUT /user_friendships(.:format) user_friendships#update
DELETE /user_friendships(.:format) user_friendships#destroy
Run Code Online (Sandbox Code Playgroud)
你可以看到它并没有显示在我的佣金路线上
这是我对routes.rb的代码
resource :user_friendships do
member do
put :accept
end
end
Run Code Online (Sandbox Code Playgroud)
如果你们可以帮我解决这个问题,那将会很棒,请注意我是一个铁杆初学者,只是按照我朋友给我的教程,所以我在修复教程附带的错误方面遇到了麻烦这看起来有点老了,再次感谢!
我目前正在整理一些用于练习的mvc框架,我有一些laravel经验,因此大致基于此。我做了一个路由器,它只是为您设置的网址返回一个指定的视图。
现在,我还制作了控制器,用于拆分URL,并将基本URL后的第一部分用作控制器,第二部分用作操作。这将加载与控制器相对应的文件,并在该文件中加载与操作相对应的方法。
因此,如果url类似于:url.com/users/index,它将加载UsersController.php文件并在该文件中查找index()方法。
现在我想知道控制器和路由器之间的确切区别是什么?它像指定的吗?其中路由器稍微简单一点,并且只对给定的确切网址做出反应,而路由器将其切碎并增加深度?
我目前所拥有的似乎有很多重叠。
从员工维护视图保存数据后,我尝试重定向到员工详细信息视图.我想在控制器的成功方法中做到这一点:
$scope.insertEmployee = function (employee) {
if (employee && $scope.IsNew) {
employeeFactory.insertEmployee(employee)
.success(function (data) {
// after a successful save, redirect the user to the details view
$location.path('/employee-details/' + employee.EmployeeNumber);
if (!$scope.$$phase)
$scope.$apply()
})
.error(function (error) {
$scope.status = 'Unable to save the employee data: ' + error;
});
}
else {
$scope.status = 'You are missing required information!';
}
};
Run Code Online (Sandbox Code Playgroud)
这是我的工厂:
factory.insertEmployee = function (employee) {
url = baseAddress + "employee/insert/";
return $http.post(url, employee);
};
Run Code Online (Sandbox Code Playgroud)
我的asp.net webapi控制器:
[Route("api/employee/insert/")]
public …Run Code Online (Sandbox Code Playgroud) 在我的控制器中,我想在我的视图中发送一条消息:
res.status(400).view('memberRegisterView',{error : "error"});
Run Code Online (Sandbox Code Playgroud)
我想用法语翻译这个错误并且有"错误".
我编辑了i18n.js:
locales: ['en', 'fr'],
defaultLocale: 'fr'
Run Code Online (Sandbox Code Playgroud)
在我的en.json中:
"error":"error"
Run Code Online (Sandbox Code Playgroud)
在我的fr.json中:
"error":"erreur"
Run Code Online (Sandbox Code Playgroud)
如何在我的控制器中使用翻译?
我一直试图this.getView()在我的控制器上使用几次,但我总是在我的控制台上得到getView不是函数错误.
有什么"技巧"或我可以做些什么来使这项工作?
Heres是我如何使用它的一个例子(这是我在我的控制器中创建的一个函数):
formatIconStatus: function(status){
var view = this.getView();
if (status != null){
if (status == "YES"){
status = "sap-icon://accept";
}else{
status = "sap-icon://error";
}
return status;
}
},
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我明白如果我想在PrestaShop中创建自己的模板变量,我会使用这样的代码:
$this->context->smarty->assign( 'varName', 'varValue' );
Run Code Online (Sandbox Code Playgroud)
我也明白添加它的正确方法是将它放入控制器......这一切都有效......
我无法弄清楚的是如何在一个地方做到这一点,但仍然能够访问所有模板中的模板变量(我的主题的.tpl文件)?
PS:将它添加到所有控制器似乎是多余的...我试图谷歌它,但我想我把坏关键字搜索...
controller ×10
php ×2
view ×2
angularjs ×1
arguments ×1
factory ×1
ios ×1
java ×1
link-to ×1
node.js ×1
prestashop ×1
redirect ×1
restful-url ×1
routes ×1
sails.js ×1
sapui5 ×1
silex ×1
smarty ×1
spring-boot ×1
swift ×1
templates ×1
this ×1
url ×1
url-routing ×1