ruby - rails I18n wrong parameter order in route (id as locale and id is nil) -
i want internationalize external code (see github) i18n rails. have read guide rails internationalization (i18n) api. translating text not problem, underlying code seems not work anymore in situations. unfortunately, i'm not rails/ruby expert.
from log:
fatal -- : actionview::template::error (no route matches {:action=>"edit", :controller=>"plans", :format=>nil, :id=>nil, :locale=>115} missing required keys: [:id]):
so problem is, parameter id (=115) passed locale instead id.
to i18n working added following code app/controllers/application_controller.rb:
... before_action :set_locale protected def set_locale i18n.locale = params[:locale] || i18n.default_locale end def default_url_options(options = {}) { locale: i18n.locale }.merge options end ...
moreover, wrapped original routes in config/routes.rb:
dmptool2::application.routes.draw scope "(:locale)", locale: /en|de/ lot of original routes end end
therefore, question is, there missing route or there problem inside code or fault. besides translating text , buttons, haven't changed original code. original routes.rb can found on github (sry, can't post link because don't have enough reputation). suggestions / perfect.
edit think i'm little bit closer. maybe it's more clear, why isn't working. first of "full" stacktrace:
f, [2015-05-04t16:43:58.600384 #19289] fatal -- : actionview::template::error (no route matches {:action=>"edit", :controller=>"plans", :format=>nil, :id=>nil, :locale=>#<plan id: 158, name: "asdfe", requirements_template_id: 59, solicitation_identifier: "", submission_deadline: nil, visibility: :public, created_at: "2015-05-04 14:41:33", updated_at: "2015-05-04 14:43:48", current_plan_state_id: 300>} missing required keys: [:id]): 2: 3: plan "<%= @vars[:plan].name %>" has been completed. 4: 5: if have questions pertaining action, please visit dmp overview page @ <%= edit_plan_url(@vars[:plan]) %> 6: 7: <%= render :partial => 'users_mailer/notification_boilerplate.text.erb' %> app/views/users_mailer/dmp_owners_and_co_committed.text.erb:5:in `_app_views_users_mailer_dmp_owners_and_co_committed_text_erb__754483862330985648_69917281861000' app/mailers/users_mailer.rb:32:in `notification' app/models/concerns/plan_email.rb:50:in `block in email_dmp_saved' app/models/concerns/plan_email.rb:49:in `email_dmp_saved' app/models/plan_state.rb:31:in `update_current_plan_state' app/controllers/plan_states_controller.rb:97:in `create_plan_state' app/controllers/plan_states_controller.rb:73:in `committed'
if hit "done" button on webpage, function committed
called, wich calls create_plan_state(:committed)
. within definition of create_plan_state, there statement plan_state = planstate.create( plan_id: @plan.id, state: state, user_id: current_user.id)
. triggers callback after_create: update_current_plan_state
:
def update_current_plan_state #update current plan pointer in plan model p = self.plan p.current_plan_state_id = self.id p.save! end
now, triggers after_save: email_dmp_saved
:
def email_dmp_saved ... if current_state.state == :committed users = self.users users.delete_if {|u| !u[:prefs][:dmp_owners_and_co][:committed]} users.each |user| usersmailer.notification( user.email, "plan completed: #{self.name}", "dmp_owners_and_co_committed", {:user => user, :plan => self } ).deliver end
i think definition of notification not important. 3rd last line calls "dmp_owners_and_co_committed", defined as:
hello <%= @vars[:user].full_name %>, plan "<%= @vars[:plan].name %>" has been completed. if have questions pertaining action, please visit dmp overview page @ <%= edit_plan_url(@vars[:plan]) %> <%= render :partial => 'users_mailer/notification_boilerplate.text.erb' %>
and in _notification_boilerplate.text.erb there is:
you may change notification preferences @ <%= edit_user_url(@vars[:user].id) %>#tab_tab2 .
i think problem edit_plan_url
, edit_user_url
. because if add random text parameter works...:
edit_plan_url("de",@vars[:plan]) , in _notification: edit_user_url("de",@vars[:user].id)
the question is, why working? there way print created route? because in stacktrace route doesn't match because format , id nil. want see new route in order know random string "de" placed.
looks routes expecting 2 params, , ordering comes. there's way avoid using named hash params passed:
edit_plan_url(id: @vars[:plan].id)
the rails automagic use symbol identify param , avoid problem.
Comments
Post a Comment