2014-10-27 53 views
0

我在我的应用程序中有一个命名空间管理员,在这里你可以删除一个客户端,这很好。 在应用程序的管理员之外,@current_user有机会编辑客户的地址。命名空间管理之外的更新记录[rails]

我不知道如何访问它并将新更新保留到数据库。这是我迄今为止

products_controller.rb(其中部分是从渲染)

class ProductsController < ActionController::Base 
    layout "application" 
    def index 
     @products = Product.all 
    end 

    def show 
     @products = Product.all 
     @current_user = Client.find_by(id: session[:client]) 
    end 
end 

_overlay_checkout.html.erb(此填充与客户端的形式从数据库地址,如果其没有更新,他们可以改变它。)

<%= simple_form_for([:admin, @current_user], :url => edit_admin_client_path) do |f| %> 
     <%= f.text_field :address %><br /> 
     <%= f.text_field :address_line_2 %><br /> 
     <%= f.select(:state, options_for_select(us_states, "CA")) %> <br /> 
     <%= f.text_field :zipcode %><br /> 
     <%= f.text_field :city %><br /> 
     <%= f.submit %> 
    <% end %> 

IM不确定如何更新此记录,...没有在应用程序的管理部分是,..任何帮助,将不胜感激。

回答

0

我在这种情况下所做的一件事是在我的控制器操作中指定@submit_url作为实例变量。

class ProductsController < ApplicationController 
def show 
    @submit_url = client_path(@client) 
end 
end 

您可以可以将此变量传递给你的form_for调用就像这样:

<%= simple_form_for([:admin, @current_user], :url => @submit_path) do |f| %> 
    <%= f.text_field :address %><br /> 
    <%= f.text_field :address_line_2 %><br /> 
    <%= f.select(:state, options_for_select(us_states, "CA")) %> <br /> 
    <%= f.text_field :zipcode %><br /> 
    <%= f.text_field :city %><br /> 
    <%= f.submit %> 
<% end %> 

如果@submit_url不是零则表单动作将被否则将其设置为@submit_url的价值将设置为您指定的基于资源的路线。这意味着在管理控制器中根本不需要改变。只需要备用控制器(在本例中为products_controller),您希望将表单提交到除自动生成的足智多谋之外的其他位置。