Not able to render partial using facebox with rails - ruby-on-rails-3.1

I am using facebox to get some information in a popup window.
I have got facebox.js and facebox.css file in my assets folder. I have included this code in my application.js file
jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox()
});
I have link_to which looks like this <%=link_to "Create",new_activities_path, :rel => "facebox" %>
When I click on the create link I get a popup which is empty and does not render the form which is in the partial.
I am able to render this partial without facebox. I have been looking all over the net but it seems the documentation of facebox is not that good.
Can anyone guide me?
Thanks,

Was able to do it by tweaking the code little bit :-
now my link_to looks like this <%=link_to "Create",new_activity_path, :remote => true %>
I also have a new action in the controller and a corresponding new.js.erb file which has got the below mentioned code:-
$.facebox('<%= escape_javascript(render :partial => 'new') %>')
the code in the application.js remains the same. I am able to render the partial in _new.html.erb in a nice popup.
Hope it will be useful to others as the documentation of facebox is very poor.
Thanks,

Related

How do I display content from a Wiki page in another page in redmine?

I'm trying to display content from one wiki page in redmine in my welcome/index file.
I've tried linking pages with [[foo]] (which I have found out only works in the wiki itself) and !{{include(projectname:stuff)}}, but when I try to use this, my redmine only displays it as plain text.
<div class="splitcontentright">
<div class="news box">
<h3><%=("News")%></h3>
!{{include(MyWikiPage:MyArticle))}}
<%= call_hook(:view_welcome_index_right, :projects => #projects) %>
</div>
</div>
Is this the wrong method? Is there another way to achieve what I'm trying to do?
After skimming trough redmines code I found the solution.
Instead of writing
!{{include(MyWikiPage:MyArticle)}}
you'll have to write:
<%= textilizable "{{include(Project:Article)}}" %>
this calls the textilizable function which let's you use wiki macros from wherever you want.

Middleman Blog: Custom layout not loading

In Middleman, I am trying to set up a blog site, using custom layout for the blog. My problem is that the main layout is loading, but the blog layout for my articles is not. The article files are being served in with their plain body.
In source/layouts/ I have two files: layout.erb and article_layout.erb.
My intent is to use article_layout.erb for my blog articles.
In config.rb I have the following:
activate :blog do |blog|
blog.sources = "articles/{category}/{year}-{month}-{day}-{title}.html"
blog.layout = "article_layout"
end
I have also tried moving article_layout.erb to source/articles/ as well as prepending the config.rb file like this: blog.layout = "layouts/article_layout"
Another failed approach is to comment out the above option and configure the layout by adding this line instead: page "/articles/*", layout: "article_layout".
So far none of these approach show a difference. Since the default layout is not being rendered I would expect some sort of error message if the path to the layout cannot be found, but nothing shows up.
I managed to replicate your problem with my own Middleman blog setup.
The docs are unclear on this because there is a broken link in the layout section of Blogging.
You need to use the nested layout feature of Middleman and wrap your custom layout in:
<% wrap_layout :layout do %>
<% end %>
So your article_layout.erb would look something like this:
<% wrap_layout :layout do %>
<div class="article-container">
<article>
<h2 class="article-title"><%= current_page.title %></h2>
<%= yield %>
</article>
</div>
<% end %>
And keep your custom layout in the source/layouts folder.
Here are the docs for Nested Layouts for your reference.
I hope this helps.

Ruby - rails - how to create automatic hyperlinks for urls in the text/string rendered on the view?

How to create automatic hyperlinks for urls in the text/string rendered on the view?
I have a page that renders user activity log and in that log/text/string there are some random urls which I want to automatically hyperlink to open in a new browser window. There is this auto_link in ruby rails, how do I use that?
text = "User xyz accessed url - http://www.something.com on 04/13/2012 00:13:18GMT"
<%= "#{Text}" %>
I want this rendered with a hyperlink to the url. The URL could be anything anywhere in the text.
Use auto_link like this:
<%= auto_link(text) %>
If you want the generated links to open new browser windows (or tabs) add the option like so:
<%= auto_link(text, :html => { :target => '_blank' }) %>
As mentioned by pjumble in the comments, auto_link is no longer a part of Rails core as of Rails 3.1, this gem brings it back: https://github.com/tenderlove/rails_autolink Thanks pjumble!
For faster parsing, try https://github.com/vmg/rinku
require 'rinku'
Rinku.auto_link(text, mode=:all, link_attr=nil, skip_tags=nil)
Also one often need more filters than just linking, for example Youtube embedded videos. For this use: https://github.com/dejan/auto_html

Rails 3 - link/button to run ajax request without redirecting

What's the best way for a link to run an ajax command (I'm using jquery in Rails 3.1)? So far I am trying to use a link to run code via the controller action "update_me."
views/products/new.html.erb has the following line:
<%= link_to "Update", :action => 'update_me' %>
In my products controller, I have:
def update_me
logger.debug 'ajax code will be here'
end
But this gives a missing template error:
Template is missing
Missing template products/update_me, application/update_me with {:handlers=>[:erb, :builder, :coffee], :formats=>[:html], :locale=>[:en, :en]}. Searched in: * "/home/ubuntu/code/preevio/app/views" * "/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/devise-1.4.3/app/views"
Why do I need to have a update_me.html.erb in my views? I assume that's what they want. Can't I just launch the code in the controller action/method without having to have a view for it? Or am I approaching this the wrong way?
I know this answer is a bit late, but I post it for anyone else who may get here trying to do something similar.
If you change your line of html to
<%= link_to "Update", :action => 'update_me', :remote => true %>
That should have the link to the provided action and do the ajax call for you.
You can look at the provided link to see the docs.
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
Since Rails has convention over configuration, Rails expects an appropriate view for the action in the controller.
If you want to render nothing:
http://guides.rubyonrails.org/layouts_and_rendering.html#using-render
render :nothing => true

ruby on rails fleximage plugin

How do I display the image in a view?
The documentation says:
<%= image_tag formatted_photo_path(#photo, :jpg) %>
This is not what I want.
I just want to display an image on a view I don't care about the url.
E.g., Avatar.
Do I need to write a path to the directory or is a method already made?
/public/images/avatar/id
Thank you
Does the example above not render something like this to the view?
<img src="/path-to-generated-image.jpg"/>

Resources