Created
March 26, 2012 18:28
-
-
Save anonymous/2208505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The controller method for the same is as below | |
def update_additional_details | |
@user = current_user | |
@user.profile.display_education_details(show_details_for_profile?(:education)) | |
@user.profile.display_experience_details(show_details_for_profile?(:experience)) | |
@user.profile.display_linkedin_details(show_details_for_profile?(:linkedin_profile)) | |
@user.profile.detail[:linkedin_profile][:data] = params[:linkedin_profile_data] | |
@user.profile.save | |
redirect_to additional_details_user_path(@user), :notice => _("successfully_updated") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Profile < ActiveRecord::Base | |
belongs_to :user | |
# SERIALIZED ATTRIBUTES | |
serialize :detail, Hash | |
# Serialized Preferences column - uses UserPreference class. | |
serialize :preferences, ProfilePreference | |
# VALIDATIONS | |
validate :url_valid, :on => :update | |
def url_valid | |
url = URI.parse(get_linkedin_profile) | |
unless %w( http https ).include?(url.scheme) && (url.hostname.include? "linkedin") && !url.path.blank? | |
errors.add(:detail, "Please Enter a Valid Linkedin Profile URL") | |
end | |
rescue URI::InvalidURIError => e | |
errors.add(:detail, "Please Enter a Valid Linkedin Profile URL") | |
end | |
end | |
=begin | |
In the view I have something like this | |
= simple_form_for(@user, :url => update_additional_details_user_path(@user), ) do |f| | |
fieldset | |
= render "shared/error_messages", :target => @user | |
Its actually user.profile so I am passing user object and shared/error_messages looks like this : | |
- if target.errors.any? | |
#errorExplanation.alert.alert-error.inline_notification | |
h5 = _("activerecord.errors.template.header", :model => target.class.model_name.human, :count => target.errors.size) | |
ul.unstyled | |
- target.errors.full_messages.each do |msg| | |
li = msg | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment