I’m new to rails and using a simple mailer function to pass a few attribute accessors through to a email template I have.
My model looks like this:
class Model < ActiveRecord::Base
attr_accessor :replace_1, :model_id
end
My controller looks like this:
def model_replace
@model= Model.find(params[:model][:model_id])
UserMailer.replacement_model(@model).deliver
respond_to do |format|
format.html { redirect_to({ :action => "model_replace"}, :notice => 'Model has been replaced.') }
end
end
My Form looks like this:
# Form stuff bound to Model
<div class="radio"><%= f.check_box :replace_1 %></div>
<%= f.hidden_field(:model_id, :value =>model.id)
My mailer works fine and passes the model to the following simple .erb file:
<p>Hello, the value of replace_1 is <%=@model.replace_1 %></p>
I know the model is being passed through as I am able to access “@model.User.user_id” for example, successfully.
Also in the rails terminal I can see the data being submitted – “model” => { “replace_1” => “1” }
Could some one help me, I’m returning a blank value for the replace_1 in my erb file.
thanks.
I solved this by adding the parameter into my controller via:
I then simply accessed it in my .erb file via:
@model.replace_1
Seems a bit dirty, but it’s working. Hope it helps anyone stuck with this newbie issue, and I’m open to any improved methods at performing this functionality.
Thanks!