]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/diary_entry_controller.rb
Fix rubocop warnings
[rails.git] / app / controllers / diary_entry_controller.rb
index bf9f2a9a24975ffaad3f40e6a9da1a880f40d940..8863e2fd9f2de594797e9561af339acd13f753ab 100644 (file)
@@ -12,7 +12,7 @@ class DiaryEntryController < ApplicationController
   def new
     @title = t "diary_entry.new.title"
 
   def new
     @title = t "diary_entry.new.title"
 
-    if params[:diary_entry]
+    if request.post?
       @diary_entry = DiaryEntry.new(entry_params)
       @diary_entry.user = @user
 
       @diary_entry = DiaryEntry.new(entry_params)
       @diary_entry.user = @user
 
@@ -35,7 +35,7 @@ class DiaryEntryController < ApplicationController
     else
       default_lang = @user.preferences.where(:k => "diary.default_language").first
       lang_code = default_lang ? default_lang.v : @user.preferred_language
     else
       default_lang = @user.preferences.where(:k => "diary.default_language").first
       lang_code = default_lang ? default_lang.v : @user.preferred_language
-      @diary_entry = DiaryEntry.new(:language_code => lang_code)
+      @diary_entry = DiaryEntry.new(entry_params.merge(:language_code => lang_code))
       set_map_location
       render :action => "edit"
     end
       set_map_location
       render :action => "edit"
     end
@@ -102,7 +102,7 @@ class DiaryEntryController < ApplicationController
 
   def list
     if params[:display_name]
 
   def list
     if params[:display_name]
-      @this_user = User.active.find_by_display_name(params[:display_name])
+      @this_user = User.active.find_by(:display_name => params[:display_name])
 
       if @this_user
         @title = t "diary_entry.list.user_title", :user => @this_user.display_name
 
       if @this_user
         @title = t "diary_entry.list.user_title", :user => @this_user.display_name
@@ -128,7 +128,7 @@ class DiaryEntryController < ApplicationController
         return
       end
     else
         return
       end
     else
-      @entries = DiaryEntry.joins(:user).where(:users => { :status => %w(active confirmed) })
+      @entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] })
 
       if params[:language]
         @title = t "diary_entry.list.in_language_title", :language => Language.find(params[:language]).english_name
 
       if params[:language]
         @title = t "diary_entry.list.in_language_title", :language => Language.find(params[:language]).english_name
@@ -150,7 +150,7 @@ class DiaryEntryController < ApplicationController
 
   def rss
     if params[:display_name]
 
   def rss
     if params[:display_name]
-      user = User.active.find_by_display_name(params[:display_name])
+      user = User.active.find_by(:display_name => params[:display_name])
 
       if user
         @entries = user.diary_entries
 
       if user
         @entries = user.diary_entries
@@ -162,7 +162,7 @@ class DiaryEntryController < ApplicationController
         return
       end
     else
         return
       end
     else
-      @entries = DiaryEntry.joins(:user).where(:users => { :status => %w(active confirmed) })
+      @entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] })
 
       if params[:language]
         @entries = @entries.where(:language_code => params[:language])
 
       if params[:language]
         @entries = @entries.where(:language_code => params[:language])
@@ -218,6 +218,8 @@ class DiaryEntryController < ApplicationController
   # return permitted diary entry parameters
   def entry_params
     params.require(:diary_entry).permit(:title, :body, :language_code, :latitude, :longitude)
   # return permitted diary entry parameters
   def entry_params
     params.require(:diary_entry).permit(:title, :body, :language_code, :latitude, :longitude)
+  rescue ActionController::ParameterMissing
+    ActionController::Parameters.new.permit(:title, :body, :language_code, :latitude, :longitude)
   end
 
   ##
   end
 
   ##