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 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题
  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开