> On Apr 10, 2016, at 5:01 PM, David Williams <li...@ruby-forum.com> wrote:
> 
> Walter Davis wrote in post #1182743:
>>> 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
>> 
>> Walter
> 
> Thank you for helping me again. I've added a modal.html.erb file. I 
> included all of the code needed for the modal itself.
> 
> Inside of the show action for the posts_controller.rb
> 
> def show
>    @post = Post.find(params[:id])
>    @new_comment = Comment.build_from(@post, current_user.id, "")
>    respond_to do |format|
>      format.html
>      format.js { render layout: false , template: 'modal'}
>      format.json {render json: @post }
>    end
>  end
> 
> But, for whatever reason, the link_to image_tag button is targeting the 
> old show.html.erb action for the post.

Please have a look at this very simple Rails scaffold app with a modal: 
https://github.com/walterdavis/modal-test

git clone it, rake db:migrate, rails s, and look at it in a browser. Add some 
posts, then return to the index page and click on the Show link and then the 
Modal link (they are different). See how the modal appears and shows you any 
post you click on when you use the modal link.

Walter

> 
> -- 
> 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+unsubscr...@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/0f7aa11a00f7a07a00e83fc6167dae38%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+unsubscr...@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/6569B707-6500-41B3-B4BA-B7DCBB976EE5%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to