Created
February 12, 2013 07:58
-
-
Save amite/4760854 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def create | |
| topic = params[:topic_name] | |
| @topic = Topic.find(params[:topic_val]) if params[:topic_val]!="" | |
| if topic != "" and params[:link][:url_link]!= "" and data=check_url | |
| if @link= Link.find_by_url_link(params[:link][:url_link]) | |
| #after upgrading to rails4 use this line instead of previous line:) | |
| #if @link= Link.find_by url_link: params[:link][:url_link] | |
| if @link.topics.exists? slug: topic.parameterize | |
| flash[:notice]="Link already submitted to the topic" | |
| else | |
| @link_user = @link.link_with_topic!(topic, current_user,@topic) | |
| if params[:comment_body] != "" | |
| comment = @link.comments.build(body: params[:comment_body]) | |
| comment.user = current_user | |
| comment.save | |
| end | |
| flash[:success]="Link submitted" | |
| publish_to_fb | |
| end | |
| else | |
| @link = current_user.links.build(params[:link]) | |
| unless /youtube.com|vimeo.com|twitter.com|soundcloud.com/.match(params[:link][:url_link]) | |
| img = link_image(data) | |
| if img | |
| @link.picture = img if /^(http|https):\/\/|[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}(:[0-9]{1,5})?(\/.*)?$/.match(img) | |
| end | |
| if data.xpath('//meta[@property="og:description"]').first | |
| @link.description = data.xpath('//meta[@property="og:description"]').first.attribute('content').value | |
| elsif data.xpath('//meta[@name="description"]').first | |
| @link.description = data.xpath('//meta[@name="description"]').first.attribute('content').value | |
| end | |
| end | |
| if @link!= nil && @link.save | |
| @link_user = @link.link_with_topic!(topic, current_user, @topic) | |
| publish_to_fb | |
| if params[:comment_body] != "" | |
| comment = @link.comments.build(body: params[:comment_body]) | |
| comment.user = current_user | |
| comment.save | |
| end | |
| flash[:success]="Link submitted" | |
| publish_to_fb | |
| end | |
| end | |
| else | |
| flash[:error]= "Enter a proper url with topic name" | |
| end | |
| respond_to do |format| | |
| format.html { redirect_to root_url } | |
| format.js | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment