Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
where does that #user in the code in check_ammo come from?
see code for "weapon" in model, controller, mailer and schema.rb
rails for zombies code
That code cant be right.
Weaponmailer
def low_ammo(weapon, zombie)
attachments["weapon.jpg"] = weapon.picture_file
mail to: zombie.email, subject: "#{weapon.name} has low ammo"
end
expects 2 parameters in controller
WeaponMailer.low_ammo(#user).deliver
#user is not defined unless its defined in ActiveRecord::Base what is not the case i think. Its just broken code example
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
i have a module like this, where "partners_url" is a routing helper method
module A
def B
....partners_url
end
end
but i get this
NoMethodError - undefined method
How can i call that url helper in side a module?, thanks.
Put this line under your module declaration
include Rails.application.routes.url_helpers
Read about other options here
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
please I need a little help... I don't know what I'm doing wrong but I need just a simple select query with Active Record. This looks my code:
Model:
class Kiosk < ApplicationRecord
#kiosk = Kiosk.all
end
Controller:
class KioskController < ApplicationController
def kiosk
#kiosk = Kiosk.all
end
end
HAML:
##kiosk
And it just doing nothing. Even if I change a password of database there isn't any error with connection. rake db:migrade was done a db was created.
Thanks
You may want to look at your logs (eg Rails.root => logs/development.log) or the output in your terminal – are there any error messages? If you log in to your console with eg rails console and run #kiosks = Kiosk.all – what are you seeing? or how about Kiosk.count –– is it showing that there are any kiosks? As mentioned the model looks funny... not sure why you have the #kiosk = Kiosk.all line in there at all....
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Inside a mailer file, I have 11 methods all of which start with the line
#reservation = reservation
Is there a way to make this DRY? I tried the following:
def set_reservation
#reservation = reservation
end
and then
before_action :set_reservation
Unfortunately, this always gave me something along these lines:
AgentReservationMailer#send_reserve_complete_mail: processed outbound mail in 1.7ms
NameError: undefined local variable or method `reservation' for #<AgentReservationMailer:0x007ffc9ae5bb38>
I'm still a very junior level developer, but I would like to try and make things look as professional as I can - is what I am trying to do even possible though?
The reason you're seeing the error is that the mailer does not know of a variable reservation inside the set_reservation method. I'm assuming that the 11 methods you mention, which use the
#reservation = reservation
take reservation as an argument. As it stands, there really is no need to try and reduce duplication.
As a side note, DRY is not a principle you should follow blindly. If you had a couple of lines that were the same in each method, then that would indeed justify an "extract method" refactoring. But replacing that #reservation = reservation assignment with e.g. a method call set_reservation(reservation), you'd still end up repeating one line across all methods.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have data I'm getting in my controller and want to display it in the view. I've tried using a helper method but no luck. I've also tried an instance variable but still doesn't work.
You can do so like this :
class SomeClass < ApplicationController
def index
#something = 'This is a cool text'
end
end
In the index.html.erb you can do this :
<%= #something %>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I tried several things and I can't seem to find the reason why Time::days_in_a_month is not found.
I'm trying to calculate the amount of signups for each day of the year, this is the code:
require 'date'
require 'time'
class GraphicsController < ApplicationController
def year_graph(year=2013)
data=calculate_signups(year)
gon.data=data
end
def calculate_signups(year)
#binding.pry
month_days=(1..12).map{|x| Time.days_in_a_month(x,year)}
total_yeardays=month_days.sum
year_sum=Array.new
day_sum={day:0,yearday:0,num:0}
afee=User.clients.year(year)#.month(month)
month_days.each_with_index do |mindex,mdays|
(1..mdays).each do |d|
day_fees=afee..month(mindex).day(d)
dia=day_sum.dup
suma=day_fees.length
dia[:day]=d
dia[:num]=suma
dia[:yearday]=Date.new(year,mindex,d).yday
year_sum << dia
end
end
year_sum
end
end
If I try it in the debugger pry(see binding.pry line) there is no problem. And of course no problem either when I try it on the console rails c --sandbox. I assume I'm missing something, but I don't know what!
The correct syntax is without a. The correct is
Time.days_in_month