Rendering another model's views

I want to render Model B's views inside Model A's, how would I do this?

For instance, I want to display the "new.html.erb" of Model B in A's
index.html.erb, and be able to create new B's in A.

Thanks.

Views correspond to controllers, not models. If that is what you mean, in Controller A, you can redirect_to B, use render :controller => :B, :action => :new, or just move new.html.erb into A’s views. Unless you are also using it for B alone, this makes more sense

Sean Clark Hess wrote:

Views correspond to controllers, not models. If that is what you mean,
in
Controller A, you can redirect_to B, use render :controller => :B,
:action
=> :new, or just move new.html.erb into A's views. Unless you are also
using it for B alone, this makes more sense

On Tue, Jul 15, 2008 at 4:50 PM, Justin To
<rails-mailing-list@andreas-s.net>

Another option is to move the content of the view into a partial and
have each parent render the partials. So you'd have something similar to

controller A

def new
...
end

views/A/new.html.erb

render :partial => '<some path to the partial>/<some partial name>'

controller B

def new
...
end

views/B/new.html.erb

render :partial => '<some path to the partial>/<some partial name>'

If the partial you are rendering is a form, you can set instance
variables containing the controller and action to post to. I'm doing
something similar to this right now in that I have a particular form
that I am using in three different situations.

Peace,
Phillip

This is what I'm trying in \controllers\users_controller.rb:

rjs.replace_html :results, :partial => '\req_details\form'

I'm trying to render \views\req_details\_form

Thanks for the help

No error. When I click the link, it just seems as though nothing is
happening.

\views\users\_user_management.html.erb:
<%= link_to_remote( "Add requirement", :url => { :action =>
:show_add_req } ) %>

\controllers\users_controller.rb:
    def show_add_req
    if(request.xhr?)
      render :update do |rjs|
          rjs.replace_html :results, :partial => '\req_details\form' #
tried multiple things here 'form', '_form', '\req_details\form',
'\req_details\_form',...
          rjs.visual_effect(:blind_down, "results", :duration => 1)
        end
    else
      redirect_to_index and return
    end
  end

\views\req_details\_form.html.erb:
sdfkjsdlfkjsdlfkjsldkfjsdkf

That's all of the relevant code...I think.

Thanks for the help!

Justin To wrote:

\controllers\users_controller.rb:
    def show_add_req
    if(request.xhr?)
      render :update do |rjs|
          rjs.replace_html :results, :partial => '\req_details\form' #

In which file is a dom element with the id 'results' defined? Is it in
the current page at the time of the ajax request?

Peace,
Phillip

Phillip Koebbe wrote:

Justin To wrote:

\controllers\users_controller.rb:
    def show_add_req
    if(request.xhr?)
      render :update do |rjs|
          rjs.replace_html :results, :partial => '\req_details\form' #

In which file is a dom element with the id 'results' defined? Is it in
the current page at the time of the ajax request?

Peace,
Phillip

The 'results' <div> is in index.html.erb

Justin To wrote:

Phillip Koebbe wrote:

Justin To wrote:

\controllers\users_controller.rb:
    def show_add_req
    if(request.xhr?)
      render :update do |rjs|
          rjs.replace_html :results, :partial => '\req_details\form' #

In which file is a dom element with the id 'results' defined? Is it in
the current page at the time of the ajax request?

Peace,
Phillip

The 'results' <div> is in index.html.erb

Okay. Let me make sure I understand. You hit the index action which
ultimately renders the partial \views\users\_user_management.html.erb.
That partial includes the link_to_remote which calls the show_add_req
action. That action updates the results div which is part of the
index.html.erb view. So the only thing we haven't seen yet are the
contents of req_details/_form. I'm wondering if you're missing an
instance variable or something in the show_add_req action.

Phillip

Okay. Let me make sure I understand. You hit the index action which
ultimately renders the partial \views\users\_user_management.html.erb.
That partial includes the link_to_remote which calls the show_add_req
action. That action updates the results div which is part of the
index.html.erb view. So the only thing we haven't seen yet are the
contents of req_details/_form. I'm wondering if you're missing an
instance variable or something in the show_add_req action.

Phillip

\views\req_details\_form.html.erb:
sdfkjsdlfkjsdlfkjsldkfjsdkf

I just stuck that in for testing purposes...

I think the problem must be in the action show_add_req
    def show_add_req
    if(request.xhr?)
      render :update do |rjs|
          rjs.replace_html :results, :partial => '\req_details\_form'
          rjs.visual_effect(:blind_down, "results", :duration => 1)
        end
    else
      redirect_to_index and return
    end
  end

Particularly, rjs.replace_html :results (<-/users/views/index.html.erb),
:partial => ?? (<-req_details/views/_form.html.erb)

Thanks

Justin To wrote:

I think the problem must be in the action show_add_req
    def show_add_req
    if(request.xhr?)
      render :update do |rjs|
          rjs.replace_html :results, :partial => '\req_details\_form'
          rjs.visual_effect(:blind_down, "results", :duration => 1)
        end
    else
      redirect_to_index and return
    end
  end

Particularly, rjs.replace_html :results (<-/users/views/index.html.erb),
:partial => ?? (<-req_details/views/_form.html.erb)

Thanks

Hi Justin,

I think I might have an idea. Comment out the visual_effect line and try
again. I believe you're getting an error in the javascript, and you're
just not seeing it. Are you using Firebug? You would be able to see it
in there. I think your visual_effect line is incorrect at the duration.
It should have the duration in curly braces as a hash, like

rjs.visual_effect(:blind_down, 'results', {:duration => 1})

At least that's how I have always coded it. Maybe I'm wrong. It's worth
a shot, though.

Peace,
Phillip

Hi, all,

I'm new to Rails. I'm trying to build Web sites with it with FileMaker as
the back-end database.

Any of you in the RTP area of North Carolina, USA?

Sincerely,

Chris Kubica
President, Founder

Application Architects

1-888-896-4608 (Ph/Fax)
1-202-280-2042 (Int'l Ph/Fax)

http://www.applicationarch.com

Certified FileMaker Developer
FileMaker Business Alliance (FBA) Member
Certified Project Management Professional (PMP)

FDA, Part 11, GxP, HIPAA and SOX Compliance Experts

Hi, all,

I'm new to Rails. I'm trying to build Web sites with it with FileMaker as
the back-end database.

Any of you in the RTP area of North Carolina, USA?

Hi, all,

I'm new to Rails. I'm trying to build Web sites with it with FileMaker as
the back-end database.

Any of you in the RTP area of North Carolina, USA?

Sorry!

\views\users\_user_management.html.erb:
<%= link_to_remote( "Add requirement", :url => { :action =>
:show_add_req } ) %>

Let me try to understand , you said u have parent and child models/
views.
and u wish to call daughter action from parent view.

try adding controller => "daughter " to the link_to_remote url

CJ(JON)

I'm out of my league here for sure, but shouldn't that partial reference
be:

  :partial => 'req_details/form'

instead of:

  :partial => '\req_details\_form'

?

Cheers,

-Roy