ryanpback
ryanpback

Reputation: 285

Rails rendering wrong partial

I have successfully rendered an ajax request for a show controller(raffle). In the new modal, I am trying to render a partial from another controller(email) but I am getting the new form from the raffle controller. When I look in the terminal, it says that I am rendering the raffles/_new and the emails/_new, however, the email form is not showing. Here is the terminal info:

Raffle Load (0.2ms)  SELECT  "raffles".* FROM "raffles" WHERE 
    "raffles"."id" = $1 LIMIT $2  [["id", 6], ["LIMIT", 1]]
      Rendering raffles/show.js.erb
      Rendered layouts/_errors.html.erb (0.5ms)
      Rendered raffles/_form.html.erb (12.0ms)
      Rendered emails/_new.html.erb (21.5ms)
      Rendered raffles/_show.html.erb (37.5ms)
      Rendered raffles/show.js.erb (51.3ms)

My raffle controller's show action has:

def show
 @raffle = Raffle.find(params[:id])
 @email = Email.new
end

My show view:

<%= render '/emails/new', :locals => { :raffle_id => @raffle.id, :email => @email } %>

emails/new is a partial which renders 'form' and form is:

<%= form_for email do |f| %>
  <%= f.text_field :email, :placeholder => "Your Email" %>
  <%= f.hidden_field :raffle_id, :value => raffle_id %>
  <%= f.submit "Enter", :class => 'btn-pop' %>
<% end  %>

For some reason, my show is showing raffles new form rather than emails new form. Might anybody know what is going on?

Upvotes: 2

Views: 289

Answers (1)

ryanpback
ryanpback

Reputation: 285

I don't think it's the proper way because it doesn't keep my my code separated. But my work-around was to just hard code the email form into the raffle's show view.

<h3><%= @raffle.title %></h3>
<h5><%= @raffle.draw_date %> at <%= @raffle.draw_time %></h5>
<h5><strong>Raffle Closes:</strong> April 25th at 4:00 pm</h5>
<p><%= @raffle.description %></p>
<%= form_for @email, :url => new_email_path do |f| %>
  <%= f.text_field :email, :placeholder => "Your Email" %>
  <%= f.hidden_field :raffle_id, :value => @raffle_id %>
  <%= f.submit "Enter", :class => 'btn-pop' %>
<% end  %>

Upvotes: 0

Related Questions