Skip to content

Commit

Permalink
Used string interpolation in notes_controller (#11489)
Browse files Browse the repository at this point in the history
* Used string interpolation in notes_controller

* Update notes_controller.rb

* Update notes_controller.rb

* Update notes_controller.rb

* Update app/controllers/notes_controller.rb

Co-authored-by: Tilda Udufo <[email protected]>

* Update notes_controller.rb

* Update notes_controller.rb

Co-authored-by: Tilda Udufo <[email protected]>
  • Loading branch information
IdayatSanni and TildaDares authored Oct 16, 2022
1 parent 9fa50a8 commit a5d2483
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def create
return
elsif params[:draft] == "true"
token = SecureRandom.urlsafe_base64(16, false)
@node.slug = @node.slug + " token:" + token
@node.slug = "#{@node.slug} token:#{token}"
@node.save!
end

Expand All @@ -153,7 +153,7 @@ def create
if params[:event] == 'on'
@node.add_tag('event', current_user)
@node.add_tag('event:rsvp', current_user)
@node.add_tag('date:' + params[:date], current_user) if params[:date]
@node.add_tag("date:#{params[:date]}", current_user) if params[:date]
end

@node.add_tag('first-time-poster', current_user) if current_user.first_time_poster
Expand Down Expand Up @@ -273,7 +273,7 @@ def update
if request.xhr?
render plain: "#{@node.path(format)}?_=#{Time.now.to_i}"
else
redirect_to URI.parse(@node.path(format)).path + '?_=' + Time.now.to_i.to_s
redirect_to "#{URI.parse(@node.path(format)).path}?_=#{Time.now.to_i}"
end
else
flash[:error] = I18n.t('notes_controller.edit_not_saved')
Expand Down Expand Up @@ -301,13 +301,13 @@ def delete
render plain: I18n.t('notes_controller.content_deleted')
else
flash[:notice] = I18n.t('notes_controller.content_deleted')
redirect_to '/dashboard' + '?_=' + Time.now.to_i.to_s
redirect_to "/dashboard?_=#{Time.now.to_i}"
end
end
end
else
flash[:error] = I18n.t('notes_controller.more_than_one_contributor')
redirect_to '/dashboard' + '?_=' + Time.now.to_i.to_s
redirect_to "/dashboard?_=#{Time.now.to_i}"
end
else
prompt_login
Expand All @@ -328,7 +328,7 @@ def author
def author_topic
@user = User.find_by(name: params[:author])
@tagnames = params[:topic].split('+')
@title = @user.name + " on '" + @tagnames.join(', ') + "'"
@title = "#{@user.name} on '#{@tagnames.join(', ')}'"
@notes = @user.notes_for_tags(@tagnames)
@unpaginated = true
render template: 'notes/index'
Expand Down Expand Up @@ -391,24 +391,24 @@ def rsvp
# leave a comment
@comment = @node.add_comment(subject: 'rsvp', uid: current_user.uid, body: 'I will be attending!')
# make a tag
@node.add_tag('rsvp:' + current_user.username, current_user)
redirect_to URI.parse(@node.path).path + '#comments'
@node.add_tag("rsvp:#{current_user.username}", current_user)
redirect_to "#{URI.parse(node.path).path}#comments"
end

# Updates title of a wiki page, takes id and title as query string params. maps to '/node/update/title'
def update_title
node = Node.find params[:id].to_i
unless current_user && current_user == node.author
flash.keep[:error] = I18n.t('notes_controller.author_can_edit_note')
return redirect_to URI.parse(node.path).path + "#comments"
return redirect_to "#{URI.parse(node.path).path}#comments"
end
node.update(title: params[:title])
redirect_to URI.parse(node.path).path + "#comments"
redirect_to "#{URI.parse(node.path).path}#comments"
end

def publish_draft
@node = Node.find(params[:id])
if current_user && current_user.uid == @node.uid || current_user.can_moderate? || @node.has_tag("with:#{current_user.username}")
if (current_user && current_user.uid == @node.uid) || current_user.can_moderate? || @node.has_tag("with:#{current_user.username}")
@node.path = @node.generate_path
@node.slug = @node.slug.split('token').first
@node['created'] = DateTime.now.to_i # odd assignment needed due to legacy Drupal column types
Expand Down Expand Up @@ -470,11 +470,13 @@ def new_note
end

def new_preview_note
Node.new_preview_note(uid: current_user.uid,
Node.new_preview_note(
uid: current_user.uid,
title: params[:title],
body: params[:body],
main_image: params[:main_image],
location: params[:location])
location: params[:location]
)
end

def not_draft_and_user_is_first_time_poster?
Expand Down

0 comments on commit a5d2483

Please sign in to comment.