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

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上