controllers

Routing in Rails making the Username an URL:

走远了吗. 提交于 2019-11-30 20:23:01
问题 In my Rails App there is Device Model - User, and a Registry model( Each user has one registry). I wanted to change my routes so that instead of: "http://localhost:3000/registries/3" it shows: "http://localhost:3000/erinwalker" So I changed routes to match '/:name' => "registries#show" And the show action in my controller to: def show @user = current_user @user = User.find_by_name!(params[:name]) @registry = @user.registry And it works, but when I create or update the registry now first it

Too Few Arguments

♀尐吖头ヾ 提交于 2019-11-30 10:50:33
I am trying to get some Javascript working in my Rails app. I want to have my index page allow me to edit individual items on the index page, and then reload the index page upon edit. My index.html.erb page looks like: <div id="index"> <%= render 'index' %> </div> In my index.js.erb I have: $('#index').html("<%=j render 'index' %>"); and in my holders_controller: def edit holder = Holder.find(params[:id]) end def update @holder = Holder.find(params[:id]) if @holder.update_attributes(params[:holder]) format.html { redirect_to holders_path } #, flash[:success] = "holder updated") ## ^---Line 28

Passing variable from controller to view - Laravel

我们两清 提交于 2019-11-30 09:27:18
I'm trying to pass a variable from one view to a controller to another view. I'm not getting any errors, but when it gets to the last view, it doesn't show the variable like it's supposed to. In the first view, I'm just getting a name. {{ Form::open(array('route' => 'form', 'method'=>'post')) }} {{ $name = Form::text('name') }} {{ Form::submit('Go!') }} {{ Form::close() }} Here is my HomeController.php. public function view1() { return View::make('stuff'); } public function postView1($name) { return Redirect::route('view2')->with($name); } public function view2($name) { return View::make(

How to include/inject functions which use $scope into a controller in angularjs?

眉间皱痕 提交于 2019-11-30 08:46:17
I am trying to include a library of functions, held in a factory, into a controller. Similar to questions like this: Creating common controller functions My main controller looks like this: recipeApp.controller('recipeController', function ($scope, groceryInterface, ...){ $scope.groceryList = []; // ...etc... /* trying to retrieve the functions here */ $scope.groceryFunc = groceryInterface; // would call ng-click="groceryFunc.addToList()" in main view /* Also tried this: $scope.addToList = groceryInterface.addToList(); $scope.clearList = groceryInterface.clearList(); $scope.add =

Too Few Arguments

蹲街弑〆低调 提交于 2019-11-29 15:57:40
问题 I am trying to get some Javascript working in my Rails app. I want to have my index page allow me to edit individual items on the index page, and then reload the index page upon edit. My index.html.erb page looks like: <div id="index"> <%= render 'index' %> </div> In my index.js.erb I have: $('#index').html("<%=j render 'index' %>"); and in my holders_controller: def edit holder = Holder.find(params[:id]) end def update @holder = Holder.find(params[:id]) if @holder.update_attributes(params[

Custom Devise controller

半世苍凉 提交于 2019-11-29 04:25:21
I would like to customize my registrations controller for Devise in Rails. I understand that you must create a controller like this: class AccountsController < Devise::SessionsController def create super end end Well, that's all very good. But then let's say I want to fully control what happens in my #create action. How do I do that? How do I manually create a model and pass it all the params? Would Account.create(params[:account]) handle it smoothly? Is there some internal stuff going on I should know about or is my only option to call #super inside the action? As long as you fulfil your

accessing HttpContext.Request in a controller's constructor

守給你的承諾、 提交于 2019-11-28 16:58:02
I'm following this ASP.NET MVC tutorial from Microsoft : My code is slightly different, where I'm trying to access HttpContext.Request.IsAuthenticated in the controller's constructor. namespace SCE.Controllers.Application { public abstract class ApplicationController : Controller { public ApplicationController() { bool usuario = HttpContext.Request.IsAuthenticated; } } } The problem is that HttpContext is always null. Is there a solution to this? The Controller is instantiated significantly prior to the point where the Index action is invoked, and at the moment of construction HttpContext is

CodeIgniter - When using $route['(:any)'] = 'pages/view/$1' how to use other controllers?

十年热恋 提交于 2019-11-28 14:16:30
When using $route['(:any)'] = 'pages/view/$1'; and I want to use other controllers in my routing for example: $route['del/(:any)'] = 'crud/del'; it won't work. I guess it will use pages/view/del/$1 and not my crud-controller when deleting an item. How can I solve this? As indicated, $route['(:any)'] will match any URL, so place your other custom routes before the "catch-all" route: $route['del/(:any)'] = 'crud/del'; // Other routes as needed... $route['(:any)'] = 'pages/view/$1'; Umair Its hundred percent working $route['(:any)'] url is placed last in your routes file $route['(:any)/company

Access fields from another Controller in JavaFX

蹲街弑〆低调 提交于 2019-11-28 12:53:42
I'm writing small application using JavaFX but I stuck with one problem. I have fxml files: MainPane.fxml Stream.fxml Play.fxml and each of them has its own controller: MainPaneController.java StreamController.java PlayController.java Where in MainPane is: <GridPane fx:controller="model.MainController" fx:id="mainGrid" xmlns:fx="http://javafx.com/fxml" alignment="CENTER" gridLinesVisible="true"> <children> <fx:include source="Stream.fxml"/> </children> <children> <fx:include source="Play.fxml"/> </children> </GridPane> Play.fxml has this field: <TextField fx:id="searchField" text="Search"

ASP.NET MVC controllers static methods

半城伤御伤魂 提交于 2019-11-28 08:39:53
A discussion came up at work recently about why ASP.NET MVC doesn't use static methods for its controller methods. Whilst I was on the side of the fence against using static methods, the only 2 arguments I could think for non-static action methods were inheritence and the ability to mock (which inheritence gives you). What was Microsoft's design choice for non-static actions/methods over static? While I don't know minds of those that designed the ASP.NET MVC Framework here is the big one for me: An instance controller is instantiated once per request, multiple requests can be happening