While I am rendering page I got undefined method 'title' for nil:NilClass
Here is my code:
routes.rb
get 'contact-us' => "pages#contact_form"
post 'contact-us' => "pages#contact_us"
pages_controller.rb
#http://localhost:3000/contact-us
def contact_form
@page = Page.find_by_seo('contact-us')
@inquiry = Inquiry.new
end
def contact_us
@inquiry = Inquiry.new(inquiry_params)
respond_to do |format|
if @inquiry.save
InquiryMailer.welcome_email(@inquiry).deliver
format.html { redirect_to :back, success: 'Your request successfully sent.' }
format.json { render '/contact-us', status: :created, location: @inquiry }
else
format.html { render :contact_form, notice: 'Please fill all the fields.' }
format.json { render json: @inquiry.errors, status: :unprocessable_entity }
end
end
end
contact_form.html.erb
<div class="contact_left">
<ul class="contact-form_address">
<li><%= @page.title %></li>
<li><%= @page.description.html_safe %></li>
</ul>
<div class="map">
<iframe src="http://ift.tt/1YhaWG4" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
</div>
</div>
<div class="contact_right">
#Contact Form here...
</div
Please let me know how I am getting @page.title
nil value? and give me solution for that.
Aucun commentaire:
Enregistrer un commentaire