标签: controller

Ruby on Rails - 在创建用户时创建配置文件

所以基本上我已经编写了自己的身份验证而不是使用gem,所以我可以访问控制器.我的用户创建工作正常,但是当我创建用户时,我还想在我的个人资料模型中为他们创建个人资料记录.我得到它主要工作我似乎无法将ID从新用户传递到新的profile.user_id.这是我在用户模型中创建用户的代码.

  def create
    @user = User.new(user_params)
    if @user.save
        @profile = Profile.create
        profile.user_id = @user.id
        redirect_to root_url, :notice => "You have succesfully signed up!"
    else
        render "new"
    end
Run Code Online (Sandbox Code Playgroud)

配置文件创建它只是不添加新创建的用户的user_id.如果有人可以提供帮助,将不胜感激.

profile controller model ruby-on-rails

2
推荐指数
2
解决办法
6251
查看次数

MVVM的控制器

我正在一个WPF项目中,该项目杂乱地隐藏在xaml / xaml.cs和一些不十分流行的ViewModels背后。

(免责声明:直到最近,我对WPF的了解还很少。我可以相当熟练地设计和布局Window或UserControl,我认为我可以将MVVM ViewModel与View分离并进行绑定。连线,但这是我目前使用WPF的经验限制。)

我的任务是向程序中添加一些新功能,以使看起来有必要先将其转换为正确使用MVVM。

我将展示我面临的一个具体问题:

我正在使用一个名为View的视图SettingsWindow.xaml。它是一组文本框,标签和诸如此类的东西。我已经将所有View数据剥离到一个ViewModel类似于以下内容的类中:

class SettingsViewModel : ViewModelBase {

    private String _outputDirectory;
    public String OutputDirectory {
        get { return _outputDirectory; }
        set { SetValue( () => this.OutputDirectory, ref _outputDirectory, value) ); }
    }

    // `SetValue` calls `PropertyChanged` and does other common-tasks.

    // Repeat for other properties, like "Int32 Timeout" and "Color FontColor"
}
Run Code Online (Sandbox Code Playgroud)

在原始的ViewModel类中,有2种方法:ReadFromRegistry和SaveToRegistry。该ReadFromRegistry方法由ViewModel的构造函数SaveToRegistry调用,该方法由MainWindow.xaml.cs的代码隐藏调用,如下所示:

private void Settings_Click(Object sender, RoutedEventArgs e) {

    SettingsViewModel …
Run Code Online (Sandbox Code Playgroud)

wpf model-view-controller controller mvvm

2
推荐指数
1
解决办法
4604
查看次数

从laravel4中的控制器调用自定义模型的方法

我试图Email从我的模型中调用我的模型中的自定义方法SessionsController.这是我的模特

<?php

class Email extends Eloquent {
    protected $guarded = array();

    public static $rules = array();

    public function sendMail($type,$data)
    {
        echo "yes";
    }
}
Run Code Online (Sandbox Code Playgroud)

从我SessionsController想要的sendMail方法.我怎么称呼它?

php controller model function laravel

2
推荐指数
1
解决办法
9011
查看次数

Symfony 2在控制器之间共享数据

我已经开始使用Symfony 2创建一个项目.我需要在所有控制器之间共享数据.

我添加了一个扩展symfony\controller的基本控制器,我的每个控制器都扩展了这个基本控制器

class BaseController extends Controller

class HomeController extends BaseController
Run Code Online (Sandbox Code Playgroud)

这个基本控制器将用于分配全局树枝变量(我知道我可以在配置中执行此操作,但某些变量将从其他配置文件和数据库中获取).

所以我认为我可以引用容器,因为Controller是容器感知的,但是我不是在使用函数(来自构造函数).

public function __construct ()
Run Code Online (Sandbox Code Playgroud)

我看到人们提到将容器作为参数传递并提及服务但我已经看过了,无法弄明白.我想要实现的就是:

public function __construct (Container $container) {
    $container->get('twig').addGlobal('foo');
}
Run Code Online (Sandbox Code Playgroud)

php controller symfony twig

2
推荐指数
1
解决办法
4664
查看次数

如何在Grails中更改控制器名称URL?

我正在尝试更改Grails中控制器名称的默认约定.我的控制器类已命名LongNameInCamelCaseController.Grails约定优于配置设置此控制器的URL映射longNameInCamelCase.我希望这个控制器名称在url友好'long-name-in-camel-case'.

有人已经这样做了吗?

谢谢.

grails controller

2
推荐指数
1
解决办法
1015
查看次数

NullPointerException(JavaFX Label.setText())

我的javaFx应用程序出了问题.每次我调用Label的.setText()方法时,都会出现NullPointerException.这是我的代码:这是我的控制器的一个小部件:

public class HomenizerController implements Initializable{
//ArrayList zum abspeichern der Termine in Listen Form
private ArrayList<Date> dateList = new ArrayList();
//ArrayList zum ab speichern der Aufgaben in Listen Form
private ArrayList<ToDo> toDoList = new ArrayList();
private Properties prop = null;

@FXML private Label username;

private void setWelcomeTab(){
    username.setText("A");
}

private void loadProperties(String path){
    FileInputStream fis = null;
    try {
        prop = new Properties();
        fis = new FileInputStream("src/homenizer/profiles/"+path+"/config.properties");
        prop.load(fis);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(HomenizerController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) …
Run Code Online (Sandbox Code Playgroud)

label controller javafx nullpointerexception fxml

2
推荐指数
1
解决办法
1万
查看次数

如何在Laravel 4中的控制器内部所有方法之前运行代码?

我有内容控制器与REST方法(index..create..store ..),我想在运行任何这些方法之前运行一些代码.

我想要做的是为我的布局设置var,其中一些数据与Content controller中的所有方法相关:

$this->layout->myvar = 'some-data';
Run Code Online (Sandbox Code Playgroud)

我试着这样做:

class ContentController extends BaseController {
    function __construct() {
        $this->layout->myvar= 'some-data';
    }
..
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用.我得到"尝试分配非对象的属性"错误.

php controller before-filter laravel laravel-4

2
推荐指数
1
解决办法
3088
查看次数

如何在rails控制器中将数据"保存"到数据库中?

我在rails控制器中收到ajax数据.我:updatedFunds进入了params,并且我将用户的美元列值设置为等于它的值 - 但它不会持续存在!

def update_dollars
    @user = User.find(params[:user_id])
    new_dollars = params[:updatedFunds]
    @user.dollars = new_dollars.to_i

    #store to database?
end
Run Code Online (Sandbox Code Playgroud)

这是最后一步吗?

ruby persistence controller ruby-on-rails save

2
推荐指数
1
解决办法
6773
查看次数

Rails link_to无法在按钮元素中工作

我有以下HTML和.erb代码:

<button type="button" class="btn btn-default btn-lg"><%= link_to "Customer Information", customer_information_path %></button>
Run Code Online (Sandbox Code Playgroud)

链接呈现正常,但单击时不执行任何操作.

这是我的路线文件:

  devise_scope :user do
   root :to => "devise/sessions#new"
  end

  get "hub" => "pages#hub"
  get "customer_information" => "pages#customer_information"
Run Code Online (Sandbox Code Playgroud)

这是我的页面控制器:

class PagesController < ApplicationController

 def hub
 end

 def customer_information
 end

end
Run Code Online (Sandbox Code Playgroud)

代码不会抛出任何错误.

思考?

ruby controller routes ruby-on-rails link-to

2
推荐指数
1
解决办法
7213
查看次数

Magento adminhtml布局更新

我正在尝试在管理页面中获取布局.

如果我在我的控制器(Highor_Plugin_StatisticsController)中执行var_dump,那么我会看到转储.

这是我到目前为止:

应用程序/代码/本地/ Highor /插件的/ etc/config.xml中

  <?xml version="1.0"?>
<config>
    <modules>
        <highor_plugin>
            <version>1.0.0</version>
            <depends>
                <!-- no dependencies -->
            </depends>
        </highor_plugin>
    </modules>
    <global>
        <models />
        <blocks />
        <resources />
        <extraconfig />
        <helpers>
            <highorplugin>
                <class>Highor_Plugin_Helper</class>
            </highorplugin>
        </helpers>
    </global>
    <admin>
        <routers>
            <highorplugin>
                <use>admin</use>
                <args>
                    <module>Highor_Plugin</module>
                    <frontName>highorplugin</frontName>
                </args>
            </highorplugin>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <highor_plugin>
                    <file>highorplugin.xml</file>
                </highor_plugin>
            </updates>
        </layout>
    </adminhtml>
</config>
Run Code Online (Sandbox Code Playgroud)

应用程序/设计/ adminhtml /默认/缺省/布局/ highorplugin.xml

<?xml version="1.0"?>
<layout>
    <highorplugin_statistics_index>
        <reference name="content">
            <block type="core/template" name="highor" template="highor/plugin.phtml" />
        </reference>
    </highorplugin_statistics_index>
</layout>
Run Code Online (Sandbox Code Playgroud)

应用程序/设计/前端/基/默认/模板/ highor/plugin.phtml

一些文字......

layout templates controller magento adminhtml

2
推荐指数
1
解决办法
9118
查看次数