Facebooker2 returning users UID but not name - heroku

I am just using the standard Facebooker2 setup.
<%= fb_connect_async_js %>
<% if current_facebook_user %>
<%= "Hello #{fb_name(current_facebook_user, :useyou => false)}!" %>
<%= fb_logout_link("Logout", request.url) %><br />
<% else %>
<%= fb_login_and_redirect('/login', :scope => 'user_about_me') %>
<% end %>
What displays on the page is:
Hello <fb:name uid="73648576" useyou="false"></fb:name>
I am sure there's something very basic wrong here, but I've followed the instructions, done tutorials, wetc. and continue to get this result.
Any help most appreciated!

Not sure why fb_name isn't working, but you could use the other method as specified in the readme. In this case, you need to call the fetch method on current_facebook_user first:
<% if current_facebook_user %>
<% current_facebook_user.fetch %>
<%= "Welcome #{current_facebook_user.first_name} #{current_facebook_user.last_name}!" %>
Ref: http://www.engineyard.com/video/21045039 (around 9:36)

Related

Middleman shows syntax error when using a link_to block

I'm using Middleman 4.2 with Middleman-blog 4.0.2.
When I have:
<% blog.tags.each do |tag, articles| %>
<%= link_to "#{tag.titleize} - #{articles.size}", tag_path(tag) %>
<% end %>
I get the desired <a> element output:
Test Tag - 1
But when I change the link_to to a block:
<% blog.tags.each do |tag, articles| %>
<%= link_to tag_path(tag) do %>
<%= tag.titleize %> - <%= articles.size %>
<% end %>
<% end %>
I get a syntax error:
/source/blog/index.html.erb:43: syntax error, unexpected ')' ...<< ( link_to tag_path(tag) do ).to_s; #_out_buf << '
I can't seem to figure out why I'm not able to get the same output here.
Any pointers?
I just realized I had the wrong erb tag on the line with the link_to helper.
The correct code looks like this:
<% blog.tags.each do |tag, articles| %>
<% link_to tag_path(tag) do %>
<%= tag.titleize %> - <%= articles.size %>
<% end %>
<% end %>

Tell <%= ... %> not to add a space

I use the following code in a template to render a date:
<% if job.end_month do %>
<%= "#{job.end_month}/" %>
<% end %>
<%= "#{job.end_year}" %>
This results in 3/ 2014 and not in 3/2014. How can I force Phoenix not to add a space after "#{job.end_month}/"?
One solution would be to create an external helper that did this for you:
e.g.
def job_string(%Job{end_month: nil}), do: job.end_year
def job_string(job), do: "#{job.end_month}/#{job.end_year}"
Then just use that in your view:
<%= job_string(job) %>
Alternatively if you don't want to do all that and would prefer a messier sort of look:
<% if job.end_month do %>
<%= "#{job.end_month}/#{job.end_year}" %>
<% else %>
<%= "#{job.end_year}" %>
<% end %>

Heroku will not render 'paginate.render' correctly

I'm using kaminari, everything works fine locally. On heroku, any code written inside the standard kaminari paginator.render block is not getting rendered.
consider
<%= paginator.render do %>
<h1> this is the paginator</h1>
<nav class="text-center">
<ul class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| %>
<% if page.left_outer? || page.right_outer? || page.inside_window? %>
<%= page_tag page %>
<% elsif !page.was_truncated? %>
<%= gap_tag %>
<% end %>
<% end %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
</nav>
<% end %>
I added the <h1>this is the paginator</h1> to tinker with what is happening. My logs look clean, there is not issue. am I missing something really obvious here? I've looked at the kaminari docs and given things are working locally, I'm not entirely sure what to look at on heroku, any pointers would be much appreciated.
snap, this hurted, my collection didn't have enough objects in it, therefore, kaminari had nothing to paginate. #usererror

add form (non-nested) dynamically in rails

pls can someone explain how I can dynamically add another copy of a form in rails?...been working on this for almost 2hrs. I messed around with .clone() and .appendTo in jquery, but it didnt work. Also, most of the materials I found online (like on railscast #196 and stackoverflow) focused heavily on nested forms. My form is nested, but I actually just want to add the parent form again. The photos which are nested use the html multiple attributes so I'm guessing that will handle multiple files upload for each parent form (btw I'm using paperclip).
If I just need to modify the railscast code please let me know.
Thanks.
<%= form_for(#user_book, html: { multipart: true }) do |f| %>
<% if #user_book.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user_book.errors.count, "error") %> prohibited this user_book from been saved:</h2>
<ul>
<% #user_book.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<p>hello</p>
<% end %>
</ul>
</div>
<% end %>
<%= f.text_field :title, placeholder: "enter title...", id: "book_title" %>
<%= f.text_field :category, placeholder: "enter category..." %>
<%= file_field_tag 'user_book[user_book_photos_attributes][][photo]', :multiple => true do |p| %>
<%= p.file_field :photo %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

Bizarre behaviour in a nested form - need <%= not <%

I'm using rails 3.1.3
I was trying to make a nested form - I made it work in the end, so I've got all the accepts_nested_attributes_for bits right.
This is the form that worked:
<%= form_for(#article, :as => :article) do |f| %>
......some article fields in here
<%= f.fields_for :article_site_permissions do |builder| %>
<%= builder.label :name %><br />
<%= builder.text_field :name %>
<% end %>
<div class="actions">
<%= f.submit 'Update' %>
</div>
<% end %>
The weird bit is that the line <%= f.fields_for :article_site_permissions do |builder| %> needed <%= not <%. All the examples I've seen (eg http://railscasts.com/episodes/196-nested-model-form-part-1?view=asciicast) can use <% not <%=. Coincidently, later that day the same thing happened on a colleagues project, which prompted this question.
Does anyone know what's going on here?
From rails 3.0 onwards <%= is the right thing to do (see the release notes). The railscast you link to predates rails 3.0.

Resources