weixin_33720956 2017-03-29 17:35 采纳率: 0%
浏览 34

Rails渲染错误的部分

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?

  • 写回答

1条回答 默认 最新

  • ?yb? 2017-03-29 18:18
    关注

    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  %>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀