controller

Why won't ternary operator work with redirect

我们两清 提交于 2019-12-04 05:27:18
问题 I love the ternary operator. It really cleans up the code look, but I have a case where it won't behave correctly in a Rails controller. I get a syntax error: unexpected tSYMBEG, expecting keyword_do or '{' or '(' I consistently get this issue, it light switches on changing the statement below to a ternary operator. It always happens when I'm trying to use it in conjunction with a redirect statement. Am I unaware of a rule about this? if nexti==0 then redirect_to :back else redirect_to edit

Laravel Controller update method not working

空扰寡人 提交于 2019-12-04 05:03:13
问题 I am new in Laravel. I made controller, Model and views by way/generator by composer php artisan generate:scaffold cities and Its index page (Create and store method) Working well but I don't know what is the problem with update method. This is my CitiesController method( Update ): public function update($id) { $city = City::findOrFail($id); $validator = Validator::make($data = Input::all(), City::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput()

Execute shell from controller CakePHP 3.x

我的未来我决定 提交于 2019-12-04 05:01:36
问题 I have a specific task in a CakePHP Shell and it's executed by a CRON job. But I want the users to be able to execute it from a web interface (like a button or something like this) whenever he wants. So, my question is, is this possible to execute a shell from a controller ? Emulate this in a controller: bin/cake MyShell I know it was possible in the previous versions of CakePHP, but I didn't find something related to this in the newest version. And use exec("bin/cake MyShell") seems really

Extend magento core controller (Checkout/OnepageController)

有些话、适合烂在心里 提交于 2019-12-04 04:14:43
问题 I am having problems while overriding a core controller. I want to add a new function but it only works if I do it in the core file (code/core/checkout/controllers/onepagecontroller.php). I have followed some post, but it's not working. Some of them are: http://www.magentocommerce.com/boards/viewthread/32979/P0/ http://www.webspeaks.in/2011/03/override-controllers-in-magento.html www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a

Access to request source IP in Spring 3 MVC web application

蹲街弑〆低调 提交于 2019-12-04 03:42:11
Is there any way in Spring 3 MVC to gain access to the request header information (like source IP address etc.), when parsing a request in a @Controller? You can retrieve it from HttpServletRequest , using getRemoteAddr() to get access to user IP address and getHeader() to get header value. For example @Controller public class MyController { @RequestMapping(value="/do-something") public void doSomething(HttpServletRequest request) { final String userIpAddress = request.getRemoteAddr(); final String userAgent = request.getHeader("user-agent"); .... } } You may pass other parameters to the

Symfony2 access user and doctrine in a service

只谈情不闲聊 提交于 2019-12-04 03:38:51
I'm running the equivalent of this code in lots and lots of controller actions, basically it grabs the user's username, and if that username is attached to a blog entity it will allow the user to see the blog entity(s): $em = $this->getDoctrine()->getManager(); $user = $this->get('security.context')->getToken()->getUser(); $entities = $em->getRepository('MySiteBundle:Blog')->findBy(array('user' => $user)); return $this->render('MySiteBundle:Blog:index.html.twig', array( 'entities' => $entities, I want to move it into a service so I can cut down on code repetition. I want to avoid doing as much

Rails Functional Test of Arbitrary or Custom URLs

筅森魡賤 提交于 2019-12-04 03:38:28
I have a RESTful resource in my Rails app called "Photo". I'm using Paperclip to serve different "styles" of my photos (for thumbnails and the like), and I'm using a custom route to RESTfully access those styles: map.connect "photos/:id/style/*style", :controller => "photos", :action => "show" That's working fine, but I want to write a test to make sure it stays that way. I already have a functional test to call the Photo controller's show action (generated by scaffold in fact): test "should show photo" do get :show, :id => photos(:one).to_param assert_response :success end That tests the

URI::InvalidURIError: bad URI(is not URI?) testing Rails controllers

南楼画角 提交于 2019-12-04 02:53:07
问题 I get URI::InvalidURIError testing Rails Home controller: require 'test_helper' class HomeControllerTest < ActionDispatch::IntegrationTest test "should get index" do get :index assert_response :success end end get the following error: E Error: HomeControllerTest#test_should_get_index: URI::InvalidURIError: bad URI(is not URI?): http://www.example.com:80index test/controllers/home_controller_test.rb:7:in `block in <class:HomeControllerTest>' The stack is the following: Rails 5.0.0.beta3

AngularJS : pass data from controller to controller without factory, service or broadcast?

江枫思渺然 提交于 2019-12-04 02:13:15
问题 I don't want to use a service or a factory and would like to pass for example an array of data. I would like to access data in my parent controller from my child component. Factory and service are excluded since i eventually want to migrate my app to angular 2, and i don't want to use ngclick which seems inseperable with broadcast/up/on. If anyone knows how to pass data on the background (without user interaction, like input or ngclick) using broadcasting, it would work aswell :) What are my

How to get list of values which are selected in radio button after click on submit in Angular js

别说谁变了你拦得住时间么 提交于 2019-12-04 02:13:07
问题 Here is the HTML, this file is partial where global controller is defined in home page:message object contains data which is loaded from first page . <ng-repeat data in message> <input type="radio" ng-model="accountValue" value="{{data}}" name="select" /> {{data.Type}} {{data.Number}} Continue JS: myApp.controller('myCtrl',['$scope',function ($scope) { $scope.selectAccount = function(id) { alert(id); } }]); I am getting id as undefined . Please help. thanks 回答1: So as per the comments what