加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Rails 4应用程序中添加新页面

发布时间:2020-12-17 03:49:51 所属栏目:百科 来源:网络整理
导读:我有新的Rails项目,在项目中我有一个名为Customer的控制器,视图和模型.现在,我需要的是,除了CRUD操作,我需要添加两个新页面,如: 1. http://0.0.0.0:3000/Customer/sale2. http://0.0.0.0:3000/Customer/lease 我想在这些文件中插入代码. 我如何实现这一点我
我有新的Rails项目,在项目中我有一个名为Customer的控制器,视图和模型.现在,我需要的是,除了CRUD操作,我需要添加两个新页面,如:

1. http://0.0.0.0:3000/Customer/sale

2. http://0.0.0.0:3000/Customer/lease

我想在这些文件中插入代码.
我如何实现这一点我的意思是创建新的销售和租赁链接?

解决方法

在routes.rb文件中,您可以添加以下两个路由:

resources :customers do
    collection do
      get 'create_sale' => 'customers#create_sale',as: :create_sale
      get 'create_lease' => 'customers#create_lease',as: :create_lease
    end
  end

然后,您可以在customers_controller.rb文件中添加两个新方法(操作):

def create_sale
    # your logic goes here
  end

  def create_lease
    # your logic goes here
  end

并在app / views / customers /目录中为它们创建两个视图,如create_sale.html.erb和create_lease.html.erb,您将在其中放置与视图相关的代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读