如何在RhoMobile的现有模型中添加.erb文件 [英] How to add .erb file in existing model in rhoMobile

查看:132
本文介绍了如何在RhoMobile的现有模型中添加.erb文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的应用程序,并编辑了index.erb文件,这样我就可以看到一个带有文本框和按钮的简单视图.

I have created a simple application and edited the index.erb file so that I have a simple view with a text box and a button.

现在,当我单击该按钮时,我希望它导航到新视图. 我知道我们可以添加模型,并且在这些模型中,我们具有不同的.erb文件. 但是我想创建一个.erb文件或将其添加到现有模型中,以便我可以更改编辑视图并在按下按钮时调用该视图.

Now when i click on that button i want it to navigate to a new view. I know that we can add models and in that models we have different .erb files. but i want to create a single .erb file or add it to an existing model so that i can change edit the view and call that view as i press the button.

就像我们要创建模型的每个屏幕一样吗?

Is it like for every screen we have to create a model??

我不知道该怎么做,到目前为止,我尝试搜索但没有帮助.

I dont know how to do the same, i tried searching but no help so far.

推荐答案

并不是每个屏幕都需要创建模型,而是相反.您需要为其创建接口的每个模型都将创建视图.

It is not that for every screen you've to create a model rather the reverse. Every model for which you need interfaces you'll create views.

为什么不先从本指南入手,并逐步了解基础知识.

Why don't you start with this guide and move ahead understanding the basics.

除CRUD接口外?您可以将视图文件直接添加到与该模型关联的控制器的视图文件夹中.例如,如果模型在app/models中为post.rb,并且在app/controllers中具有对应的控制器posts_controller.rb,并且在app/views/posts中具有对应的视图,则可以将视图与相应的视图一起添加到app/views/posts文件夹中控制器中的方法将渲染该视图,前提是在config/routes.rb文件中存在用于该视图的路由.

Other than CRUD interfaces? You can add a view file directly to the view folder of the controller this model is associated with. For example, if the model is post.rb in app/models and it has a corresponding controller posts_controller.rb in app/controllers and it has corresponding views in app/views/posts then you can add your view to app/views/posts folder with a corresponding method in the controller which will render that view provided there is a route for that in the config/routes.rb file.

说我想在发布中添加一个landing_page.html.erb视图.我会在posts_controller.rb中添加一个方法(尽管这不是强制性的.但是,对于呈现视图之前检查某些条件可能很有用):

Say I want to add a landing_page.html.erb view to Post. I would add a method in posts_controller.rb (although, this is not mandatory. But, might be useful for you to check some conditions before rendering the view):

class posts_controller < ApplicationController
  ...
  def landing_page
  end
end

在app/views/posts目录中添加视图:

Add a view in app/views/posts directory:

# app/views/posts/landing_page.html.erb

将路由添加到config/routes.rb文件:

Add a route to the config/routes.rb file:

map.resources do
  member do
    get :landing_page
  end
end

现在,您可以在http://localhost:3000/posts/:id/landing_page上访问该页面.

Now, you can access the page at http://localhost:3000/posts/:id/landing_page.

这篇关于如何在RhoMobile的现有模型中添加.erb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆