Rails Composer生成应用程序,添加动态页面,而不是从应用程序视图中产生

时间:2014-11-26 14:12:28

标签: ruby-on-rails rails-composer

我正在使用rails composer进行快速基础应用。我设置了一个带有主页的bootstrap-devise-pundit应用程序(也尝试过Home,User,About选项 - 页面在../views/pages中设置为静态)。主页是"访客"控制器和视图作为标准布局。 Rails composer将gem high_voltage用于其他页面(静态),将它们放在../views/pages文件夹中。我遇到问题的地方是添加我自己的模型/控制器/视图。不是因为他们不工作。我的问题是视图没有使用应用程序页眉/页脚进行渲染。 "访客"页面呢。不知道为什么。我可能会在这里失踪什么?

例如,

I create a model mymodel.rb in ../app/models
I create a controller mycontroller.rb in ../app/controllers
I create a view index.html.erb in ../app/views/mycontroller/

可以查询模型,查看渲染索引(显示和创建的显示和自定义操作)。但是,我没有获得应用程序标题(以及样式表/ javascript包含或页脚。

当然会欣赏一个轻推......

由于

从rails composer默认创建的应用程序布局。

root@work:/home/hackerkatt/workspace/canopy_portal# cat app/views/layouts/application.html.erb 
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= content_for?(:title) ? yield(:title) : "Canopy Portal" %></title>
    <meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Canopy Portal" %>">
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
  </head>
  <body>
    <header>
      <%= render 'layouts/navigation' %>
    </header>
    <main role="main">
       <%= render 'layouts/messages' %>
       <%= yield %>
    </main>
  </body>
</html>

以下是我的应用布局。我相信我对控制器有一个看法。但是,它会在没有应用程序布局的情况下呈现。

root @ work:/ home / hackerkatt / workspace / canopy_portal#tree app /

<pre>
  app/
  ├── assets
  │   ├── images
  │   │   ├── bg_header.jpg
  │   │   ├── bullet1.gif
  │   │   ├── bullet2.gif
  │   │   ├── green_indicator.png
  │   │   ├── rails.png
  │   │   ├── red_indicator.png
  │   │   └── yellow_indicator.png
  │   ├── javascripts
  │   │   ├── application.js
  │   │   ├── canopy_aps.js
  │   │   └── progressbar.js
  │   └── stylesheets
  │       ├── application.css.scss
  │       └── framework_and_overrides.css.scss
  ├── controllers
  │   ├── application_controller.rb
  │   ├── canopy_aps_controller.rb
  │   ├── concerns
  │   └── visitors_controller.rb
  ├── helpers
  │   ├── application_helper.rb
  │   ├── layout_helper.rb
  │   └── link_to_function_helper.rb
  ├── mailers
  ├── models
  │   ├── canopy_aps.rb
  │   ├── concerns
  │   ├── gestio.rb
  │   └── user.rb
  ├── services
  │   └── create_admin_service.rb
  └── views
      ├── canopy_aps
      │   ├── index.html.erb
      │   ├── registered_sms.html.erb
      │   └── show.html.erb
      ├── devise
      │   ├── passwords
      │   │   ├── edit.html.erb
      │   │   └── new.html.erb
      │   ├── registrations
      │   │   ├── edit.html.erb
      │   │   └── new.html.erb
      │   └── sessions
      │       └── new.html.erb
      ├── layouts
      │   ├── application.html.erb
      │   ├── _messages.html.erb
      │   ├── _navigation.html.erb
      │   └── _navigation_links.html.erb
      └── visitors
          └── index.html.erb
</pre>

这是访客控制器和canopy_aps控制器

root@work:/home/hackerkatt/workspace/canopy_portal# cat app/controllers/visitors_controller.rb 
class VisitorsController < ApplicationController
end
root@work:/home/hackerkatt/workspace/canopy_portal# cat app/controllers/canopy_aps_controller.rb
class CanopyApsController < ApplicationController
  before_filter :authenticate_user!

  def initialize
    @apname = ''
  end

  def index
    canopy_aps = Gestio.getAPList()
    @canopy_aps = CanopyAPS.organize(canopy_aps)
  end

  def show
    ip = int2IPOctet(params[:id])
    @apip = ip
    @apname = params[:apname]
    @ap = CanopyAPS.getAPSubscribers(ip)
    @reg_subs = @ap.count
  end

  def registered_sms
    @canopy_aps = Gestio.getAPList()
    @reg_subs = CanopyAPS.getRegSMCounts(@canopy_aps)
    @totals = CanopyAPS.totalsByComp(@reg_subs)
  end
end

为完整起见,相关的观点......

root@work:/home/hackerkatt/workspace/canopy_portal# cat app/views/visitors/index.html.erb 
<h3>Welcome</h3>
root@work:/home/hackerkatt/workspace/canopy_portal# cat app/views/canopy_aps/index.html.erb 
<%= stylesheet_link_tag 'application' %>

<% title "Canopy Aps" %>
<h2>Canopy AP Listing</h2>
<br />

<div class="container-fluid">
<% @canopy_aps.each do |comp,data| %>
  <div style='margin:0 0 0 20px;'>
    <h2><%= comp.camelcase %></h2>
      <table class="table table-striped" style="width:700px;">
        <thead>
          <th>AP</th>
          <th>IP Addr</th>
          <th>Log into SM</th>
        </thead>
        <tbody>
          <% data.each do |ap| %>
            <tr>
              <td><%= ap.host_descr %></td>
              <td><%= int2IPOctet(ap.ip) %></td>
              <td><%= link_to "Get Subscriber List", canopy_ap_path(:id=>ap.ip, :apname=>ap.host_descr) %></td>
            </tr>
          <% end %>
        </tbody>
      </table>
    <div>
  </div>
<% end %>

如果我添加渲染布局:&#34;应用程序&#34;在动作中呈现应用程序布局,然后是动作视图。我必须将此添加到每个操作/方法以使应用程序布局呈现。网上发现的一些帖子建议使用&#39; layout&#34; application&#34;&#39;在控制器的顶部,这对我不起作用。另外值得注意。如果我向访问者控制器添加索引操作(没有定义任何操作并因此呈现默认索引视图),则应用程序布局呈现中断并且呈现的所有内容都是访问者索引视图。我想理解这一点。

class CanopyApsController < ApplicationController
  before_filter :authenticate_user!

    def initialize
        @apname = ''
    end

  def index
    canopy_aps = Gestio.getAPList()
    @canopy_aps = CanopyAPS.organize(canopy_aps)
    render layout: "application"
  end

  def show
    ip = int2IPOctet(params[:id])
    @apip = ip
    @apname = params[:apname]
    @ap = CanopyAPS.getAPSubscribers(ip)
    @reg_subs = @ap.count
    render layout: "application"
  end    

end

0 个答案:

没有答案