-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added pg gem and removed mongo db related all changes. added migratio…
…ns for User and Content models
- Loading branch information
Showing
11 changed files
with
246 additions
and
50 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
class ContentsController < ApplicationController | ||
|
||
def index | ||
#binding.pry | ||
@contents = Content.all.desc(:created_at) | ||
@con = Content.new | ||
@c = [] | ||
#@contents = Content.tagged_with_all(/#{params[:q]}/) | ||
#@conc = content_to_hash(@content_selected) | ||
end | ||
|
||
|
||
def show | ||
@content = Content.find(params[:id]) | ||
end | ||
|
||
def new | ||
@content = Content.new | ||
@con = [] | ||
end | ||
|
||
def details | ||
@content = Content.find(params[:id]) | ||
respond_to do |format| | ||
format.js {} | ||
end | ||
end | ||
|
||
def create | ||
@content = Content.new(content_params_input) | ||
@content.image_file_name = @content.title | ||
|
||
if @content.save | ||
ImageWorker.perform_async(@content.id.to_s) | ||
respond_to do |format| | ||
format.html {redirect_to contents_path} | ||
end | ||
else | ||
respond_to do |format| | ||
format.html { render action: 'new' } | ||
|
||
end | ||
end | ||
end | ||
|
||
def edit | ||
@content = Content.find(params[:id]) | ||
end | ||
|
||
def destroy | ||
@content = Content.where(id: params[:id]).first | ||
|
||
if @content.destroy | ||
redirect_to contents_path | ||
else | ||
#flash[:notice] = ' not deleted' | ||
flash.now[:error] = @content.errors.messages | ||
render action: 'index' | ||
end | ||
end | ||
|
||
|
||
def update | ||
@content = Content.find(params[:id]) | ||
@con = @content.tags.split(",") | ||
@con = tags_to_hash(@con) | ||
if @content.update_attributes(content_params_input) | ||
redirect_to contents_path | ||
else | ||
render action: 'edit' | ||
end | ||
end | ||
|
||
def tags | ||
@contents = Content.tagged_with_all(/#{params[:q]}/) | ||
@tags = @contents.collect(&:tag_map).flatten.select{|t| t[:name] =~ /#{params[:q]}/} | ||
|
||
respond_to do |format| | ||
format.html {render html: @tags} | ||
format.json { render json: @tags} | ||
end | ||
end | ||
|
||
def content_ids | ||
@tags_selected = Content.tags.select{|e| e =~ /#{params[:q]}/} | ||
@content_selected = Content.where(:tags_array.in => @tags_selected).to_a | ||
|
||
respond_to do |format| | ||
format.html | ||
format.json {render json: @content_selected} | ||
end | ||
end | ||
|
||
private | ||
def content_params_input | ||
params.require(:content).permit(:url,:photo, :title, :tags, :rates, :user_id) | ||
end | ||
|
||
def tags_to_hash(cons) | ||
cons.map do |con| | ||
{id: con, name: con} | ||
end | ||
end | ||
#not required************************************ | ||
|
||
def content_to_hash(cons) | ||
cons.map do |cons| | ||
{id: cons[:_id].to_s, url: cons.url, title: cons.title, photo_url:cons.photo.url} | ||
end | ||
#binding.pry | ||
end | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n | ||
|
||
en: | ||
devise: | ||
confirmations: | ||
confirmed: "Your account was successfully confirmed." | ||
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes." | ||
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes." | ||
failure: | ||
already_authenticated: "You are already signed in." | ||
inactive: "Your account is not activated yet." | ||
invalid: "Invalid email or password." | ||
locked: "Your account is locked." | ||
last_attempt: "You have one more attempt before your account will be locked." | ||
not_found_in_database: "Invalid email or password." | ||
timeout: "Your session expired. Please sign in again to continue." | ||
unauthenticated: "You need to sign in or sign up before continuing." | ||
unconfirmed: "You have to confirm your account before continuing." | ||
mailer: | ||
confirmation_instructions: | ||
subject: "Confirmation instructions" | ||
reset_password_instructions: | ||
subject: "Reset password instructions" | ||
unlock_instructions: | ||
subject: "Unlock Instructions" | ||
omniauth_callbacks: | ||
failure: "Could not authenticate you from %{kind} because \"%{reason}\"." | ||
success: "Successfully authenticated from %{kind} account." | ||
passwords: | ||
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." | ||
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." | ||
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." | ||
updated: "Your password was changed successfully. You are now signed in." | ||
updated_not_active: "Your password was changed successfully." | ||
registrations: | ||
destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon." | ||
signed_up: "Welcome! You have signed up successfully." | ||
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." | ||
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." | ||
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." | ||
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." | ||
updated: "You updated your account successfully." | ||
sessions: | ||
signed_in: "Signed in successfully." | ||
signed_out: "Signed out successfully." | ||
unlocks: | ||
send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes." | ||
send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes." | ||
unlocked: "Your account has been unlocked successfully. Please sign in to continue." | ||
errors: | ||
messages: | ||
already_confirmed: "was already confirmed, please try signing in" | ||
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" | ||
expired: "has expired, please request a new one" | ||
not_found: "not found" | ||
not_locked: "was not locked" | ||
not_saved: | ||
one: "1 error prohibited this %{resource} from being saved:" | ||
other: "%{count} errors prohibited this %{resource} from being saved:" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ | |
end | ||
end | ||
#root 'contents#index' | ||
mount Sidekiq::Web, at:'/sidekiq' | ||
mount Sidekiq :: Web , at : '/sidekiq' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateContents < ActiveRecord::Migration | ||
def change | ||
create_table :contents do |t| | ||
t.string :title | ||
t.string :url | ||
t.string :image_file_name | ||
end | ||
end | ||
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
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
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
This file was deleted.
Oops, something went wrong.
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