favouriting users profiles in rails - ruby-on-rails

so I've created a web app that has user profiles, where users can search for fellow users based on interests etc.. How might I add a feature where users can favorite a persons profile? I.e. User A finds User B and likes what they see, and can click a 'Favorite this profile' button and perhaps it's starred, and stored? What would the code look like for this? Just an idea, but I'm open to all ideas.
user_profile.html.erb
<%= render "shared/header" %>
<div id="landing_welcome_page">
<div class="container">
<div class="row">
<%#= Profile image upload %>
<div class="span4">
<%= user_avatar(current_user) %>
<%#= Space w line %>
<div class="name"></div><br>
<%#= Please bare in mind these are strickly temporary placeholders i.e whitespace %>
<%= render 'social' %>
</div>
<div class="span8">
<%# User name %>
<span class="name1">
<% if current_user.first_name.blank? %>
<%= current_user.first_name.present? ? current_user.first_name : link_to('Finish your profile', edit_account_path)%>
<% else %>
<%= current_user.first_name %> <%= current_user.last_name %>
<% end %>
</span>
<span class="side-buttons">
<div class="name"></div>
</span>
</span>
</div>
<div class="row">
<br />
<div class="span6">
<%# User occupation %>
<i class="fa fa-usd"></i>:
<%= best_in_place current_user, :occupation, nil: 'Add occupation' %>
</div>
<div class="addy">
<div class="span2">
<%# User address %>
<i class="fa fa-home"></i>:
<%= current_user.address.present? ? current_user.address : link_to('Add Address', edit_account_path) %>
</div>
</div>
<div class="span6">
<%# User gender %>
<br />
<% if current_user.gender == "M" || "male" %>
<i class="fa fa-male"></i> Male
<% else %>
<i class="fa fa-female"></i> Female
<% end %>
</div>
<div class="span2">
<!-- Code to calculate age by user birthday -->
<br />
Age: <%= user_birthday %>
</div>
<div class="span8"></div>
<div class="span8"><div class="name"></div></div>
<div class="span8">
<div class="tabbable"> <!-- Only required for left/right tabs -->
<ul class="nav nav-tabs">
<li class="active">About me</li>
<li>Photos</li>
<li>Personality</li>
</ul>
<div class="tab-content">
<div class="tab-pane in active" id="tab1">
<% #questions_for_about.each_with_index do |question, index| %>
<div class="question">
<h4 class="user_questions">
<%= index + 1 %>. <%= question.question %>
<%= link_to ("<i class='icon-edit'></i>".html_safe),
edit_user_question_path(current_user, question),
remote: true, class: "edit_link_#{question.id}" %>
</h4>
<div class="answer" id="answer_<%= question.id %>">
<%= answer_for(question) %>
</div>
</div>
<% end %>
</div>
<div class="tab-pane" id="tab2">
<div class="page-header">
<%= form_for Photo.new do |f| %>
<span class="btn btn-success fileinput-button">
<i class="icon-plus icon-white"></i>
<span>Add photos...</span>
<%= f.file_field :file, multiple: true, name: "photo[file]" %>
</span>
<% end %>
<div class="clearfix"></div>
</div>
<div class="photos_cont">
<div class="col-sm-6 col-md-3">
<span class="gallery"><%= render current_user.photos %></span>
</div>
</div>
</div>
<div class="tab-pane" id="tab3">
<% #questions_for_personality.each_with_index do |question, index| %>
<div class="question">
<h4 class="user_questions">
<%= index + 1 %>. <%= question.question %>
<%= link_to ("<i class='icon-edit'></i>".html_safe),
edit_user_question_path(current_user, question),
remote: true, class: "edit_link_#{question.id}" %>
</h4>
<div class="answer" id="answer_<%= question.id %>">
<%= answer_for(question) %>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>
<%= render '/shared/footer' %>
</div>
</div>
<script id="template-upload" type="text/x-tmpl">
<div class="upload">
{%=o.name%}
<div class="progress"><div class="bar" style="width: 0%;"></div></div>
</div>
</script>
<script>
var fb_param = {};
fb_param.pixel_id = '6009056882201';
fb_param.value = '0.00';
(function(){
var fpw = document.createElement('script');
fpw.async = true;
fpw.src = '//connect.facebook.net/en_US/fp.js';
var ref = document.getElementsByTagName('script')[0];
ref.parentNode.insertBefore(fpw, ref);
})();
</script>
<noscript>
<img height="1" src="https://www.facebook.com/offsite_event.php?id=6009056882201&value=0" style="display:none;" width="1"/>
</noscript>
<script type="text/javascript">
// remove default datepicker event
jQuery(document).off('best_in_place:datepicker');
jQuery(document).on('best_in_place:datepicker', function(event, bip, element) {
// Display the jQuery UI datepicker popup
jQuery(element).find('input')
.datepicker({
format: element.data('date-format')
})
.on('hide', function(){
bip.update();
})
.on('changeDate', function(){
$(this).datepicker('hide');
})
.datepicker('show');
});
</script>

Create a Favorite model with a has_and_belongs_to_many relationship with User
Once you create the Favorite model and set up the relationship, you can do things like:
#user.favorites = [ user1, user2, user3 ]
#user.favorites << user4
to assign favorites to a user, or display them with something like:
<%= #user.favorites.map(&:name).to_sentence %>
You'll find everything you need to know on how to do this here: http://guides.rubyonrails.org/association_basics.html

Related

I want to change jquery-ui sortable code into sortableJS with stimulus how can I do it

all_request.js.erb
$(function () {
$( ".kanban-card, .sub-card, .kanban-card .sub-tickets" ).sortable({
connectWith: ".kanban-card",
cancel: ".main_ticket",
start: function (event, ui) {
},
change: function (event, ui) {
},
out: function (event, ui) {
},
over: function (event, ui) {
},
receive: function (event, ui) {
}
});
});
all_request.html.erb
<div class="d-flex justify-content-around">
<% #kanban_columns.each do |col| %>
<div class="box border" data-item="<%=col.id %>">
<h3 class="text-center"><%=col.name.humanize%></h3>
<hr>
<div class="kanban-card" style="height: 770px; overflow: auto;">
<% col.client_requests.each do |interview| %>
<div class="border bg-warning bg-opacity-50 m-2">
<div class="main_ticket card m-2 border border-danger" >
<div class="card-body">
<p class="card-text mb-0">#<%= interview.id %></p>
<h5 class="card-title"><%= interview.customer_name %></h5>
</div>
</div>
<div class="sub-tickets collapse" id="Req<%= interview.id %>">
<% interview.departments.each do |dept| %>
<% if interview.kanban_column.name == 'new_request' %>
<div class="card m-2 border border-dark" >
<div class="card-body">
<p class="mb-0">dept. <%=dept.name%></p>
<p class="mb-0">no of resources: <%=dept.no_of_resources%></p>
</div>
</div>
<% end %>
<% dept.developers.each do |dev| %>
<% if col.name == dev.developer_status %>
<div class="sub-card">
<div class="card m-2 border border-dark" data-item="<%=dev.id %>">
<p class="mb-0">dept. <%=dept.name%></p>
<p class="mb-0">developer. <%=dev.name%></p>
</div>
</div>
<% end %>
<% end %>
<%end%>
</div>
</div>
<%end%>
<!--if developers exist and main ticket is in new request-->
<% #client_requests.each do |interview| %>
<% #card_id = interview.customer_name+"_#{interview.id}"+"_#{col.id}" %>
<% #card_class = interview.customer_name+"_#{interview.id}" %>
<div class="border bg-warning bg-opacity-50 m-2 card-header main-card-div" >
#id : <%=interview.id%>
<%=interview.customer_name%>
<% interview.departments.each do |dept| %>
<% dept.developers.each do |dev| %>
<% if col.name == dev.developer_status %>
<div class="m-2 sub-card" id="<%= #card_id %>">
<div class="card m-2" data-item="<%= dev.id %>">
<div class="card-body">
#id : <%=dev.id%>
<p class="mb-0">dept. <%=dept.name%></p>
<p class="mb-0">developer. <%=dev.name%></p>
</div>
</div>
</div>
<% end %>
<%end%>
<%end %>
</div>
<%end%>
<!-- -->
</div>
</div>
<% end %>
</div>
In above code div with class-name kanban-card, sub-tickets, .sub-cards are sortable so I just want same class will be sortable using sortableJs.
You can see the demo here: https://drive.google.com/file/d/15E9gT0F91mUES8gfLm1tYxUqvDGrUAjM/view?usp=sharing
resources:
sortableJs: https://github.com/SortableJS/Sortable

Rails: Cannot get tabs to work with and kaminari

I have two tabs at the profile page: tab 1) my recipes, tab 2) my favorites.
Kaminari pagination works just fine when I go to the index page for recipes. However the pagination does not work properly at the profile page. When I click on next it does show me the next page, but the pagination bar disappears. So I cannot go back, unless I refresh the page.
Who can help me? Thank you in advance.
Profile controller:
class ProfilesController < ApplicationController
def show
#recipes = current_user.recipes.order("name").page(params[:recipes_page]).per(3)
#favorites = current_user.favorites.order("name").page(params[:favorites_page]).per(3)
end
end
Kaminari:
<% if #recipes.present? %>
<div class="apple_pagination" id="paginator-my-recipes">
<%= paginate #recipes, :remote => true, :param_name => :recipes_page %>
</div>
<% end %>
app/views/profiles/show.html.erb:
<div class="container is-small sand-color">
<div class="tabs">
<div class="your-recipes-btn">
<a class= "tab active" data-target= "#your-recipes">
<h4>Your recipes</h4>
</a>
</div>
<div class="your-favorites-btn">
<a class= "tab" data-target= "#your-favo">
<h4>Favorites</h4>
</a>
</div>
</div>
</div>
<div class="tab-content" id="your-recipes">
<div class="container is-small sand-color">
<% if #recipes.present? %>
<%= render #recipes %>
<% else %>
<h4 class="text-center">Create your own recipes</h4>
<% end %>
</div>
<% if #recipes.present? %>
<div class="apple_pagination" id="paginator-my-recipes">
<%= paginate #recipes, :remote => true, :param_name => :recipes_page %>
</div>
<% end %>
</div>
<div class="tab-content hidden" id="your-favo">
<div class="container is-small sand-color">
<% if #favorites.present? %>
<%= render #favorites %>
<% else %>
<h4 class="text-center">You don't have any recipes</h4>
<% end %>
</div>
<% if #favorites.present? %>
<div class="apple_pagination" id="paginator-my-favo">
<%= paginate #favorites, :remote => true, :param_name => :favorites_page %>
</div>
<% end %>
</div>
app/views/profiles/_favorites.html.erb
<div class="product">
<div class='product-upvote'>
<div class="product-arrow"></div>
<div class='product-count'>95</div>
</div>
<% if recipe.photo != nil %>
<%= cl_image_tag recipe.photo, height: 100, width: 150, crop: :fill, class: "product-image hidden-xs" %>
<% else %>
<% end %>
<div class='product-body'>
<%= link_to recipe_path(recipe) do %>
<h4><%= recipe.name %></h4>
<% end %>
<div class="summary dont-break-out">
<p><%= recipe.summary %></p>
</div>
<div class="recipes-info">
<div class="recipes-kitchen">
<p>Gang</p>
<h5> <%= recipe.course %> </h5>
</div>
<div class="recipes-kitchen">
<p>Keuken</p>
<h5> <%= recipe.kitchen %> </h5>
</div>
<div class="cooking-time">
<p>Kooktijd</p>
<h5><%= recipe.cooking_time %> min</h5>
</div>
<div class="created">
<p>Geplaatst op</p>
<h5><%= recipe.created_at.strftime('%d/%m/%Y') %> </h5>
</div>
</div>
</div>
</div>
app/views/profiles/show.js.erb:
$('#your-recipes').html('<%= escape_javascript render(#recipes) %>');
$('#paginator-my-recipes').html('<%= escape_javascript(paginate(#recipes, :remote => true).to_s) %>');
$('#your-favo').html('<%= escape_javascript render(#favorites) %>');
$('#paginator-my-favo').html('<%= escape_javascript(paginate(#favorites, :remote => true).to_s) %>');

Add params to URL on render rails

Is it possible to add params to url while rendering view on controller?
Here I'm trying to add tab=2 on the url.So that my new url looks like localhost:3000/organizations/new?tab=2
I tried the following code
render 'organizations/new', tab: 2
but it neither change the URL nor add the params on URL it just render the view.
I also tried render 'organizations/new?tab=2' It throws ActionView::MissingTemplate.
EDIT 1
Here is my organization/new.html.erb code
<!-- START PAGE CONTAINER -->
<div class="page-container page-navigation-top-fixed" id="organization-new">
<!-- PAGE CONTENT -->
<%= render 'shared/navigation' %>
<div class="page-content">
<%= render 'shared/header' %>
<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default tab-panel">
<div class="panel-body">
<div class="tab-container" id="tabs">
<ul class="nav nav-tabs" role="tablist">
<li class="active">
<a href="#tab-1" data-toggle="tab">
<%= t('admins.create_organization') %>
</a>
</li>
<li class="disabled">
<a href="#tab-2" data-toggle="tab" class="disabled">
<%= t('organization.add_profile') %>
</a>
</li>
</ul>
<div class="org tab-content">
<div class="tab-pane fade in active" id="tab-1">
<h3></h3>
<%= render 'organizations/add_edit_org_form' %>
</div>
<div class="tab-pane fade" id="tab-2">
<h3></h3>
<%= render 'organizations/add_business_profile_tab' %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- END PAGE CONTENT WRAPPER -->
<%= render 'shared/footer' %>
</div>
<!-- END PAGE CONTENT -->
</div>
<!-- END PAGE CONTAINER -->
here is my 'organizations/add_edit_org_form' partial which is renders on first tab
<%= form_for (#organization), html: {class: 'form-horizontal organization-form', id: 'add_edit_organization'} do |f| %>
<div class="form-group">
<%= f.label(:name, t('organization.label_name'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:name, class: 'form-control', organization_id: #organization.id) %>
<span class="org-error-block text-danger text-danger" id="organization_name_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:abbreviation, t('organization.label_abbr'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:abbreviation, class: 'form-control', organization_id: #organization.id) %>
<span class="org-error-block text-danger text-danger" id="organization_abbreviation_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:organization_type, t('organization.label_type'), class: 'col-md-3
col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.select(:organization_type, options_for_organization_type, {}, class: 'form-control select') %>
<span class="org-error-block text-danger text-danger" id="organization_type_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:primary_currency, t('organization.label_primary_currency'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.select(:primary_currency, options_for_primary_currency, {}, class: 'form-control select') %>
<span class="org-error-block text-danger text-danger" id="organization_primary_currency_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:status, t('organization.label_status'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.select(:status, options_for_status, {}, class: 'form-control select') %>
<span class="org-error-block text-danger text-danger" id="organization_status_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:country_id, t('organization.label_country'), class: 'col-md-3 col-xs-12
control-label') %>
<div class="col-md-4 col-xs-12 select-country-options">
<%= f.select(:country_id, options_for_countries, {}, class: 'form-control select') %>
<span class="org-error-block text-danger text-danger" id="organization_country_id_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:payment_method_id, t('organization.label_payment_method'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.select(:payment_method_id, options_for_payment_methods, {}, class: 'form-control select') %>
</div>
</div>
<div class="panel-footer">
<button class="btn btn-primary ajax-spinner pull-right">
<%= t('organization.label_submit') %>
<span class="fa fa-floppy-o fa-right"></span>
</button>
<i class="fa fa-spinner fa-pulse fa-2x pull-right"></i>
</div>
<% end %>
and here is my another partials 'organizations/add_business_profile_tab' which is renders on second tab
<%= form_for (#business_profile), html: {class: 'form-horizontal', id: 'add_business_profile', multipart: true} do |f| %>
<div class="form-group">
<label class="col-md-3 col-xs-12 control-label"><%= t('business_profile.upload_your_logo') %></label>
<div class="col-md-4 col-xs-12 ">
<div class="image-frame" id="upload_logo_div">
<%= image_tag 'upload.jpg', class: 'image-frame', id: 'logo_image' %>
</div>
<%= f.file_field(:logo, id: 'logo_upload_btn') %>
<span class="org-error-block text-danger text-danger" id="logo_upload_btn_error"></span>
<div id="date_picker_container"></div>
</div>
</div>
<div class="form-group">
<%= f.hidden_field(:organization_id, value: #organization.id, id: 'organization_id') %>
<%= f.label(:email, t('business_profile.email'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:email, class: 'form-control', organization_id: #organization_id) %>
<span class="org-error-block text-danger text-danger" id="business_profile_email_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:address, t('business_profile.address'), class: 'col-md-3
col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:address, class: 'form-control') %>
<span class="org-error-block text-danger text-danger" id="business_profile_address_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:phone, t('business_profile.phone'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:phone, class: 'form-control') %>
<span class="org-error-block text-danger text-danger" id="business_profile_phone_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:contact_person_name, t('business_profile.contact_person_name'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:contact_person_name, class: 'form-control') %>
<span class="org-error-block text-danger text-danger" id="business_profile_contact_person_name_error"></span>
</div>
</div>
<div class="form-group ">
<%= f.label(:registration_date, t('business_profile.registration_date'), class: 'col-md-3 col-xs-12
control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:registration_date, class: 'form-control', autocomplete: 'off', value: #business_profile.registration_date.nil? ? '' : #business_profile.registration_date.strftime('%m/%d/%Y')) %>
<span class="org-error-block text-danger text-danger" id="business_profile_registration_date_error"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-4 col-xs-12">
<%= f.hidden_field(:organization_id) %>
<input type="hidden" value=<%= Date.today.strftime('%Y-%m-%d') %> name="today_date" id="today_date">
<span class="org-error-block text-danger text-danger" id="business_profile_organization_id_error"></span>
</div>
</div>
<div class="panel-footer">
<button class="btn btn-primary pull-right">
<%= t('business_profile.label_submit') %>
<span class="fa fa-floppy-o fa-right"></span>
</button>
</div>
NOTE
I want to be stay on second tab after the form submission on both success and failure cases.
try this one.
render 'organizations/new', :locals => {tab:2}
Another solution:
On new organizations link pass the tab like
link_to 'New Organization', new_organization_path(tab: 2)
This will exactly same as you want
localhost:3000/organizations/new?tab=2
Normally when render method is executed in controller, it parses the targeted view template in your case organizations/new. It has nothing to do with changing the HTTP request URL and params.
instead you do like this
form_for (#organization, url: organization_path(#organization, tab: 2) )
This will make the params tab=2 in the address bar after the completion of the request.
Moreover, it looks like the term tab=2 is not fixed, it might change at run time so you may use jQuery to modify the action attribute of the form like
$('#target_form').attr('action', old_value + '?tab=2');

Rails link a tags

I have the code below and I want to create an tag between the div with the class 'box'.
I cant just use the link_to method because I want this link to encompass all the html code from the to its respective ending . So anyone who clicks within that box gets transported to the equivalent of: <%= link_to( 'go', { action: :edit, id: course.id }) %>. I tried finding this else where but failed.
<% #courses.in_groups_of(3, false) do |group| %> <!--Takes groups of three courses -->
<div class="row">
<% group.each do |course| %>
<div class="col-xs-12 col-sm-6 col-lg-4">
<div class="box">
<div class="icon">
<div class="image"><span class="glyphicon glyphicon-list-alt btn-lg white"></span></div>
<div class="info">
<h3 class="title"><%= course.name %> | GPA: <%= course.gpa.to_f %></h3>
<p>
<%= course.description %>
</p>
<div class="more">
<a href="#" title="Title Link"><i class="fa fa-plus"></i> Details
</a>
<%= link_to( 'go', { action: :edit, id: course.id }) %>
</div>
</div>
</div>
<div class="space"></div>
</div>
</div>
<% end %>
</div>
<% end %>
<%= link_to({ action: :edit, id: course.id }) do %>
<div class="box">
<div class="icon">
<div class="image"><span class="glyphicon glyphicon-list-alt btn-lg white"></span></div>
<div class="info">
<h3 class="title"><%= course.name %> | GPA: <%= course.gpa.to_f %></h3>
<p>
<%= course.description %>
</p>
<div class="more">
<i class="fa fa-plus"></i> Details
</div>
</div>
</div>
<% end %>
I am not sure I understand your question, but I think you are asking to enclose your html code into a link_to tag. So try this:
<%= link_to path_to_land_on do %>
<div class='box'>
// other code
</div>
<% end %>
Replace path_to_land_on with { action: :edit, id: 2 } or path

Ability to only see the content of the profile that has been filled out

so I've created a web app that has user profiles, where users can search for fellow users based on interests etc.. However sometimes the users don't fill out certain areas of their profile, i.e. about me may be left blank.. So how can I add the ability for users to only see the content of the profile that they filled out. In other words they can’t see the parts of other user profiles for which they have not completed.
user_profile.html.erb
<%= render "shared/header" %>
<div id="landing_welcome_page">
<div class="container">
<div class="row">
<%#= Profile image upload %>
<div class="span4">
<%= user_avatar(current_user) %>
<%#= Space w line %>
<div class="name"></div><br>
<%#= Please bare in mind these are strickly temporary placeholders i.e whitespace %>
<%= render 'social' %>
</div>
<div class="span8">
<%# User name %>
<span class="name1">
<% if current_user.first_name.blank? %>
<%= current_user.first_name.present? ? current_user.first_name : link_to('Finish your profile', edit_account_path)%>
<% else %>
<%= current_user.first_name %> <%= current_user.last_name %>
<% end %>
</span>
<span class="side-buttons">
<div class="name"></div>
</span>
</span>
</div>
<div class="row">
<br />
<div class="span6">
<%# User occupation %>
<i class="fa fa-usd"></i>:
<%= best_in_place current_user, :occupation, nil: 'Add occupation' %>
</div>
<div class="addy">
<div class="span2">
<%# User address %>
<i class="fa fa-home"></i>:
<%= current_user.address.present? ? current_user.address : link_to('Add Address', edit_account_path) %>
</div>
</div>
<div class="span6">
<%# User gender %>
<br />
<% if current_user.gender == "M" || "male" %>
<i class="fa fa-male"></i> Male
<% else %>
<i class="fa fa-female"></i> Female
<% end %>
</div>
<div class="span2">
<!-- Code to calculate age by user birthday -->
<br />
Age: <%= user_birthday %>
</div>
<div class="span8"></div>
<div class="span8"><div class="name"></div></div>
<div class="span8">
<div class="tabbable"> <!-- Only required for left/right tabs -->
<ul class="nav nav-tabs">
<li class="active">About me</li>
<li>Photos</li>
<li>Personality</li>
</ul>
<div class="tab-content">
<div class="tab-pane in active" id="tab1">
<% #questions_for_about.each_with_index do |question, index| %>
<div class="question">
<h4 class="user_questions">
<%= index + 1 %>. <%= question.question %>
<%= link_to ("<i class='icon-edit'></i>".html_safe),
edit_user_question_path(current_user, question),
remote: true, class: "edit_link_#{question.id}" %>
</h4>
<div class="answer" id="answer_<%= question.id %>">
<%= answer_for(question) %>
</div>
</div>
<% end %>
</div>
<div class="tab-pane" id="tab2">
<div class="page-header">
<%= form_for Photo.new do |f| %>
<span class="btn btn-success fileinput-button">
<i class="icon-plus icon-white"></i>
<span>Add photos...</span>
<%= f.file_field :file, multiple: true, name: "photo[file]" %>
</span>
<% end %>
<div class="clearfix"></div>
</div>
<div class="photos_cont">
<div class="col-sm-6 col-md-3">
<span class="gallery"><%= render current_user.photos %></span>
</div>
</div>
</div>
<div class="tab-pane" id="tab3">
<% #questions_for_personality.each_with_index do |question, index| %>
<div class="question">
<h4 class="user_questions">
<%= index + 1 %>. <%= question.question %>
<%= link_to ("<i class='icon-edit'></i>".html_safe),
edit_user_question_path(current_user, question),
remote: true, class: "edit_link_#{question.id}" %>
</h4>
<div class="answer" id="answer_<%= question.id %>">
<%= answer_for(question) %>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>
<%= render '/shared/footer' %>
</div>
</div>
<script id="template-upload" type="text/x-tmpl">
<div class="upload">
{%=o.name%}
<div class="progress"><div class="bar" style="width: 0%;"></div></div>
</div>
</script>
<script>
var fb_param = {};
fb_param.pixel_id = '6009056882201';
fb_param.value = '0.00';
(function(){
var fpw = document.createElement('script');
fpw.async = true;
fpw.src = '//connect.facebook.net/en_US/fp.js';
var ref = document.getElementsByTagName('script')[0];
ref.parentNode.insertBefore(fpw, ref);
})();
</script>
<noscript>
<img height="1" src="https://www.facebook.com/offsite_event.php?id=6009056882201&value=0" style="display:none;" width="1"/>
</noscript>
<script type="text/javascript">
// remove default datepicker event
jQuery(document).off('best_in_place:datepicker');
jQuery(document).on('best_in_place:datepicker', function(event, bip, element) {
// Display the jQuery UI datepicker popup
jQuery(element).find('input')
.datepicker({
format: element.data('date-format')
})
.on('hide', function(){
bip.update();
})
.on('changeDate', function(){
$(this).datepicker('hide');
})
.datepicker('show');
});
</script>
The conditionals that you have can be expanded to cover the whole div containing the info block.
For example:
<div class="addy">
<div class="span2">
<%# User address %>
<i class="fa fa-home"></i>:
<%= current_user.address.present? ? current_user.address : link_to('Add Address', edit_account_path) %>
</div>
</div>
Could be
<div class="addy">
<% if current_user.address.present? %>
<div class="span2">
<%# User address %>
<i class="fa fa-home"></i>:
<%= current_user.address %>
</div>
<% else %>
<%= link_to('Add Address', edit_account_path) %>
<% end %>
</div>
Then it would only show the link if the address is not present.
Seems like you're on the right track. Basically, for every user attribute on the User model you want to show/hide, you'll want to add a conditional that evaluates whether or not the attribute on current_user is present?:
<span class="name1">
<% if current_user.first_name.blank? %>
<%= link_to('Finish your profile', edit_account_path) %>
<% else %>
<%= current_user.first_name %> <%= current_user.last_name %>
<% end %>
</span>
Alternatively, you can continue using ternary operators for single line evaluations, as you are already doing in some instances:
<%= current_user.address.present? ? current_user.address : link_to('Add Address', edit_account_path) %>

Resources