Ruby on Rails Sunday, April 10, 2016

> On Apr 10, 2016, at 3:57 PM, David Williams <lists@ruby-forum.com> wrote:
>
> This link is rendering the entire show action inside of the modal.
> (Including the navigation bar)
>
> <%= link_to image_tag(post.photo.url(:medium), style: 'height: 300px;
> width: 500px;'), post_path(controller: :posts, :action => :show, :id =>
> post.id), remote: true, data: {:toggle => 'modal', :target =>
> '#reusable_modal'}, lazy: true %>
>
> Should I take a different approach, than hard-coding the show action in
> the link itself.

You need a different method to render this, or if it will only ever appear in the modal, then you need to add layout: false to your controller so it doesn't render the whole page. Make sure that your `show` template only renders the stuff that will appear within the modal, nothing else, and then turn off the layout so you don't get the entire page.

If the modals will be the only consumer of the "remote: true" requests, then you can make that change in your show controller method, like this:

def show
#whatever else you regularly have here
respond_to do |format|
format.html { }
format.js { layout: false, template: 'modal' }
end
end

# views/posts/modal.html.erb

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4><%= @post.title %></h4>
</div>
<div class="modal-body">
<%= @post.whatever_else_you_want_to_render %>
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">Close</button>
</div>


Walter


>
> The JavaScript is working from what I can see.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2dbb1dc2282e02b6782d7a6432e6c8af%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/755041FE-1E68-4083-ABD9-9A45F1CB7E14%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment