Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

ruby - How to add .erb file in existing model in rhoMobile

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No you don't have to create models for each view(.erb). In case you want to add new view to existing model, just add new method(def) into the controller(.rb), and new view(.erb) with the same name as of the new method.

let say there exist a model DemoController.rb in app/Demo. you can add new method to it as like

class DemoController < Rho::RhoController
  ...
  def index
  end

  def new_method
  end

end

To navigate from the index view to the new_method, you can write

<button onclick="location.href='/app/Demo/new_method'">new method</button>

or

<button onclick="location.href='<%= url_for :action => :new_method %>'"
>new method</button>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...