我有一个像下面这样的指令,基本上用当前的一个附加一个新元素.并在新元素绑定ng-controller"openCntl"
explorerModule.controller("openCntl",function($scope, $dialog){
$scope.open = function(){
alert('dialog closed with result: ' + result);
};
});
explorerModule.directive('ngCustomerClick', function($parse){
return {
controller : "openCntl",
link: function(scope, element, attr){
var alert = angular.element(
'<div class="lp-dropdown-wrapper open" ng-controller="dialogCntl" ' +
'><div class="arrow"></div>' +
'<ul class="nav nav-tabs" style="display: inline;">' +
'<li class="add" ng-click="open()"><a tabindex="-1" href="#"><span class="icon-coffee"></span>Add</a></li>'+
'</ul></div>'
);
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是当我点击li时,不要在控制器"openCntl"中调用该函数,如何实现呢?
非常感谢
我不明白为什么我收到这个错误
undefined method `sector_id' for #<Portfolio:0x007fe17c2e3848>
Run Code Online (Sandbox Code Playgroud)
我有一个投资组合模型和一个区域模型,它们看起来像这样
class Portfolio < ActiveRecord::Base
belongs_to :sector
attr_accessible :overview, :title, :sector_id
end
class Sector < ActiveRecord::Base
has_many :portfolios
attr_accessible :name
end
Run Code Online (Sandbox Code Playgroud)
我的路线
resources :portfolios do
resources :sectors
end
Run Code Online (Sandbox Code Playgroud)
因此,在我的表单中创建一个新的投资组合,我有这个collection_select
<%= f.label :sector_id, "Choose Sector", :class => 'title_label' %><br>
<%= f.collection_select(:sector_id, Sector.all, :id, :name, :prompt => "Please Select a Sector") %>
Run Code Online (Sandbox Code Playgroud)
这是我以前做了很多次并且它已经工作了,有人能看出为什么我会收到这个错误吗?
我能想到的唯一一件事就是我把我的控制器称为投资组合,我总是混淆了复数和单一的控制器名称,这会对我的情况产生影响吗?
我正在尝试为Rails应用程序创建一系列静态页面."约"页面工作正常,但当我尝试在"条款"页面使用相同的方法时,我得到一个未知的操作.我假设这是我的控制器.
这是我的routes.rb文件:
resources :pages
get "pages/index"
match '/about' => 'pages#about'
match ':permalink', :controller => 'pages', :action => 'show', :as => 'about'
match '/terms' => 'pages#terms'
match ':permalink', :controller => 'pages', :action => 'show', :as => 'terms'
root :to => 'pages#index'
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样:
class PagesController < ApplicationController
helper_method :search_performed?
def index
@search = Farm.search(params[:q])
@json = @search.result.to_gmaps4rails
end
protected
def search_performed?
params[:q].present?
end
def about
end
def feedback
end
def terms
end
end
Run Code Online (Sandbox Code Playgroud)
知道发生了什么事吗?
如何从网址中删除控制器名称.我有两个控制器
home and admin
Run Code Online (Sandbox Code Playgroud)
和网址是
http://domain.com/likes/home/post/sports/20-Athletes-Who-Profited-While-in-College-/12
home/post
Run Code Online (Sandbox Code Playgroud)
和
http://domain.com/likes/admin/ad_managment/edit/2
http://domain.com/likes/admin/meta_tags_home/edit/2
admin/ad_managment admin/meta_tags_home
Run Code Online (Sandbox Code Playgroud)
我已经用过了
$route['(:any)/(:any)/(:num)'] = "home/post/$1";
Run Code Online (Sandbox Code Playgroud)
它适用于此URL
http://domain.com/likes/home/post/sports/20-Athletes-Who-Profited-While-in-College-/12
Run Code Online (Sandbox Code Playgroud)
管理员不工作.基本上我想删除home/post离开管理员控制器没关系
我正在尝试使用app/routes.php中的以下内容路由到RESTful控制器:
Route::controller('register', 'RegisterController');
Route::get('/', 'HomeController@showWelcome');
Run Code Online (Sandbox Code Playgroud)
在我的app/controllers/RegisterController.php文件中,我添加了以下内容:
<?php
class RegisterController extends BaseController
{
public function getRegister()
{
return View::make('registration');
}
public function postRegister()
{
$data = Input::all();
$rules = array(
'first_name' => array('alpha', 'min:3'),
'last_name' => array('alpha', 'min:3'),
'company_name' => array('alpha_num'),
'phone_number' => 'regex:[0-9()\-]'
);
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
return 'Data was saved.';
}
return Redirect::to('register')->withErrors($validator);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
当我在终端运行php artisan路线时,我得到:
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters | …Run Code Online (Sandbox Code Playgroud) 我正在创建一个简单的页面来使用md5散列字符串,但是永远不会返回输出.
这是我用于这些页面的控制器.函数md5被路由到get,函数md5post被路由到post.该视图具有发布到md5post函数的表单.它有一个变量$ input,带有要散列的字符串.
<?php
class ConversionsController extends \BaseController {
private $withmd5;
public function __construct(){
$this->withmd5 = [
'pagetitle' => 'MD5 hashing',
'description' => 'description',
'infoWindow' => 'info',
'btnSumbit' => Form::submit('Hash', ['class' => 'btn btn-default'])
];
}
public function md5(){
return View::make("layout.textareamaster")->with($this->withmd5);
}
public function md5post(){
if (strlen(Input::get("input")) > 0)
{
$hash = md5(Input::get("input"));
}
return Redirect::back()->withInput()->with("output", $hash);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是观点
{{ Form::open(['method' => 'post']) }}
<div class="row">
<div class="col-md-6">
<p class="well">
{{ Form::textarea('input', '', ['class' => 'form-control', 'rows' => 5]) …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我有两个叫做PropertiesController和的控制器FacilitiesController.创建一个propertyin之后PropertiesController,我想加载view(form)from FacilitiesController.
我尝试使用render facilities/new显示错误(表单中的第一个参数不能包含nil或为空),因为我没有初始化传递给form_for方法的参数(@facility).
我可以通过初始化@facility变量来避免上述错误PropertiesController.但我在form_for其中的代码中调用了object当前的方法FacilitiesController.我不希望所有代码再次重复PropertiesController.
如何在FacilitiesController不重复代码的情况下渲染视图?
在我的控制器中我有这个:
def hours_create
@hour = params[:hour].map { |hour_attrs| Hour.create(hour_attrs) }
if @hour.save
redirect_to :back, notice: "hour created."
else
render :new
end
end
Run Code Online (Sandbox Code Playgroud)
错误来自@hour.save但不确定要替换它的原因,因为当项目保存到我的数据库中时,我需要以某种方式重定向页面?
为什么会出现这个错误?
谢谢
我的EFService中的代码:
private IDbSet<Item> _Items;
private int _SearchTakeCount = 10;
public IList<string> SearchByArticleCount(int articleCount)
{
return _Items.AsNoTracking().Where(m => m.Articles.Count().Equals(articleCount))
.Take(_SearchTakeCount)
.Select(m => m.Articles.Count().ToString())
.Distinct()
.ToList();
}
Run Code Online (Sandbox Code Playgroud)
我的控制器中的代码:
public virtual ActionResult AutoCompleteSearch(string term, KeywordSearchBy searchBy = KeywordSearchBy.Name)
{
IList<string> data = new List<string>();
switch (searchBy)
{
case ItemSearchBy.Name:
data = _ItemService.SearchByName(term);
break;
case ItemSearchBy.ArticleCount:
int articleCount = Convert.ToInt32(term);
data = _ItemService.SearchByArticleCount(articleCount);
break;
}
Run Code Online (Sandbox Code Playgroud)
当我运行项目时,异常是有效的.这个例外是:LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式.
我想用Angular JS和Restangular将对象发送到Spring Controller.这就是我尝试这样做的方式:
var scoreTO = {
score: parseFloat($scope.score.score),
percentage: parseFloat($scope.score.percentage),
date: (new Date()).getTime()
}
Restangular.one("scores").post(scoreTO);
Run Code Online (Sandbox Code Playgroud)
有运输对象:
public class ScoreTO implements Serializable{
private double score;
private double percentage;
private long date;
public ScoreTO(){}
public ScoreTO(double score, double percentage, long date){
this.score = score; this.percentage = percentage; this.date=date;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public double getPercentage() {
return percentage;
}
public void setPercentage(double percentage) {
this.percentage = percentage;
} …Run Code Online (Sandbox Code Playgroud) controller ×10
php ×3
angularjs ×2
forms ×2
laravel ×2
ruby ×2
activerecord ×1
asp.net-mvc ×1
c# ×1
casting ×1
codeigniter ×1
converter ×1
javascript ×1
laravel-4 ×1
restangular ×1
routes ×1
spring ×1
static ×1
url ×1