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.
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
On Tue, Jul 15, 2008 at 4:50 PM, Justin To
[email protected]
Sean C. 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 senseOn Tue, Jul 15, 2008 at 4:50 PM, Justin To
[email protected]
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 => ‘/’
controller B
def new
…
end
views/B/new.html.erb
render :partial => ‘/’
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
Justin To wrote:
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
Are you getting some kind of error? Post all relevant code so we can
have a look.
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
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 K. 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’
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!
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:
Phillip K. 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,
PhillipThe ‘results’
is in index.html.erbOkay. 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
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
endParticularly, 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
On Wed, 2008-07-16 at 21:27 -0400, Chris K. wrote:
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?
I remember you from my filemaker days.
Heavily suggest that you learn rails with sql db first so that you get
the power of rails before you attempt to connect to a Filemaker DB
because that’s likely to be disappointing (wouldn’t know, I never
tried).
Once I got into Rails, Filemaker seemed so painful and I have stopped
doing Filemaker.
Craig
On Wed, 2008-07-16 at 21:27 -0400, Chris K. wrote:
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?
oh and by the way…start your own threads - don’t steal other people’s
threads by clicking ‘reply’ and changing the subject.
Craig
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 K.
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
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
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs