how can i use fb_server_fbml helper method in facebooker2? - ruby-on-rails-3

I am developing a facebook app using rails 3 and facebooker2
i cannot find any example on how to use fb_server_fbml helper method.
what is "proc" in its paramter. Can anyone provide me with sample code?
Thanks

The &proc parameter is used as a content block that is inserted between the <fb:serverFbml> tags. You can learn more about block helpers and differences between Rails 2.3 and Rails 3 here: Block Helpers in Rails 3
So, try something like this:
<% fb_server_fbml do %>
<%#Insert here your content %>
<% end %>
If you want to use the request form, try the following:
<% fb_server_fbml do %>
<% fb_request_form("Your app name","http://www.example.com/callback","Try this out!") do %>
<%= fb_multi_friend_selector("Invite your friends:", {:rows => 3}) %>
<% end %>
<% end %>

Related

Forms on partial doesn't render properly

I have a Rails app that is running fine on Rails 3.x and ActiveAdmin 0.6.6. However I want to upgrade it to Rails 5 and ActiveAdmin 1.x. I started the upgrade process first upgrading from 3.x to 4.x and then to 5x, and with ActiveAdmin I tested with 1.0.0 and now I'm using the master from Github.
Everything worked fine with the App in both Rails versions and ActiveAdmin but the ActiveAdmin forms that are in a partial.
The problem is the following:
I have a file app/admin/menu.rb whose has a partial views/admin/menus/_form.html.erb.
The partial contains the form of the Menu.
This is the contents of the partial (views/admin/menus/_form.html.erb):
<%= semantic_form_for [:admin, #menu], builder: ActiveAdmin::FormBuilder do |f| %>
<% f.inputs 'Campos Menu' do %>
<% f.input :project if current_admin_user.admin? %>
<% f.input :title %>
<% f.input :title_en %>
<% f.input :item %>
<% f.input :icon, as: :file %>
<% end %>
<% f.inputs 'Submenus' do %>
<% f.has_many :submenus, heading: '' do |fa| %>
<% fa.input :title, as: :string %>
<% fa.input :title_en, as: :string %>
<% fa.input :kind, as: :select, collection: Submenu.kind_collection %>
<% fa.input :items_as, as: :select, collection: Submenu.items_as_collection %>
<% end %>
<% end %>
<% f.actions do %>
<% f.action :submit %>
<% end %>
<% end %>
The render result of this file is only the 'actions' buttons, in this case the 'submit' button. The interesting thing is that if I remove the <% f.actions do %>... from the partial then the <% f.inputs 'Submenus' do %> gets rendered and the same if I remove the later. In other others is being rendered on the last block that contains an end.
The same behaviour is being observed on Rails 4.x and 5.x (except Rails 5.1.x which I didn't tested).
If I move the form from the partial to the app/admin/menu.rb it gets rendered properly. This could be a solution for me however I have others forms that make use of JQuery for fields manipulation and other stuff on the front end.
As I said before, all these forms partials were working properly on Rails 3.x and ActiveAdmin 0.6.6.
Anyone knows what's the problem?
DISCLAIMER: I'm not a Rails or ActiveAdmin expert, so bear with me if is a silly mistake related to this issue.
Yes, it's activeadmin#3486 I'm glad you figured out the workaround. I'm curious if this Arbre branch fixes it for you. Glad to see people still upgrading, I'll do what I can to help.
The solution that I found was to put a = for the <% f.input(s) %> on the partial. Having something like this <%= f.inputs ... %> instead of this <% f.inputs ... %> solves the problem.

rails render model with location

I have a Picture model and i'd like to use <%= render #pictures %> in my view in order to display them.
I also want the pictures to be arranged as 3 columns across the screen.
If I use the render how can I know which picture I am rendering in order to know where to place it? (such as in a table or some other arrangement that is not 1 dimensional)
Is there a way to make the rendering automation to have a counter?
<% #pictures.each_index do |i| %>
<% #some routine here %>
<%= render #pictures[i] %>
<% end %>
I would suggest using each_with_index instead:
<% #pictures.each_with_index do |picture, i| %>
<%= render picture, :i => i %>
<% end %>
Notice that you can pass index to the partial as well.

Correctly generate a form builder object while discarding the HTML without a deprecation warning

I have a partial which generates a div with some form fields in it. It uses the form builder variable "f" which is provided as input to correctly name the fields in the parameter has (fields are actually nested attributes, so the name is like "[author][book][0][title]").
I want to use that same partial when receiving an AJAX call to regenerate the div based on new user information. I am currently using <% form_for ... |f| %> in my erb file, but that generates a warning that "<% %>" is deprecated.
My erb file looks like the following:
<% if f.nil? %>
<% form_for(#author, :id => :coupon_form) do |f| %>
<%= render "books_detail1", :f => f %>
<% end %>
<% else %>
<%= render "books_detail1", :f => f %>
<% end %>
So what is the correct way to create a form builder context while discarding the generated HTML?
The correct answer is to use fields_for. It generates the same form builder object without the html. I lost track of this in it's use for sub-forms, but it's really the same thing.

Partial in rails 3 application renders :per_page times while using will_paginate

I am using will_paginate in my rails 3 application.
In my Controller i have a line as
def index
#blogs = Blog.paginate(:per_page => 5, :page => params[page])
end
And in my index.html.erb
<div>
<% if #blogs.size.zero? %>
No Blogs Found
<% else %>
<%= render #blogs if #blogs %>
<% end %>
</div>
<%= will_paginate #blogs%>
And in my partial _blog.html.erb
<% #blogs.each do |blog| %>
<%= link_to blog.title, blog_path(blog.id)%>
<% end %>
When i run the app by $rails s
The partial displays the contents per_page times..
For the first page it displays for 5 times ..
How to avoid so ..
Give me some suggestions...
EDIT
I changed the partial code in _blog.html.erb to
<%= link_to blog.title, blog_path(blog.id)%>
which is the right one as already by default rails 3 will send the collection #blogs to the partial noneed for the loop in the partials ..
When render is passed a collection, it automatically renders the partial multiple times.
Therefore you want your partial _blog.html.erb to just be:
<%= link_to blog.title, blog_path(blog.id)%>
You don't need an each statement there because the render statement takes care of this.
See 3.4.5 "Rendering Collections" in http://guides.rubyonrails.org/layouts_and_rendering.html

Is it possible to use partials to be rendered as wrappers in Rails?

I would like to render structures like this:
<tag1>
<tag2 someattribute="somevalue">
<.. lot of things inside ..>
</tag2>
</tag1>
<tag1>
<tag2 someattribute="someothervalue">
<.. different inside things inside ..>
</tag2>
</tag1>
The tag1, tag2 are the same, they are just parametrized. The inner part of the code changes. I tried to implement the thing above like that (haml):
%div{id:['products', id]}
.products_content
%div{id:['products', id, 'content'], class:'products_mask'}
= yield
This was the partial _content_head.html.haml, which is called from a template:
= render 'shared/content_head', id: 'all' do
%h3= Title
%p= Body of the text.
My theory that yield inside the partial would lead to rendering of the passed block did not prove. Is there a way to use partials as code wrappers? Can you suggest me some solution how to reach this? Thank you.
This might be a good use of the capture method.
I'm only familiar with ERB, but here is the general idea:
<% structure = capture do %>
<h3>Title</h3>
<p>Body of text</p>
<% end %>
Then pass the variable into the partial:
<%= render 'shared/content_head', :structure => structure %>
And within the partial, spit out the structure variable:
<%= structure %>
Reset structure multiple times within the view as you render partials (or maybe more appropriately, in a helper?).
I've used the following (Rails 4, but I think it should work with Rails 3 too):
<%# app/views/users/_edit.html.erb %>
<%= render layout: 'modal_wrapping' do |f| %>
<%= f.input :email %>
...
<% end %>
.
<%# app/views/users/_modal_wrapping.html.erb %>
<div id='modal'>
<%= simple_form_for #user do |f| %>
<%= yield f %>
<% end %>
</div>