Help with create action in a different show page

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-06-14T17:25:18Z Indexed on 2010/06/14 17:32 UTC
Read the original article Hit count: 226

Filed under:

Hi, I'm a Rails newbie and want to do something but keep messing something up. I'd love some help.

I have a simple app that has three tables. Users, Robots, and Recipients. Robots belong_to users and Recipients belong_to robots.

On the robot show page, I want to be able to create recipients for that robot right within the robot show page.

I have the following code in the robot show page which lists current recipients:

<table>

<% @robot.recipients.each do |recipient| %>
  <tr>
    <td><b><%=h recipient.chat_screen_name %></b> via <%=h recipient.protocol_name</td>

    <td><%= link_to 'Edit', edit_recipient_path(recipient) %>&nbsp;</td>
    <td><%= link_to 'Delete', recipient, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

What I'd like to do is have an empty field in which the user can add a new recipient, and have tried the following:

I added this to the Robots Show view:

<% form_for(@robot.recipient) do |f| %>
Enter the screen name<br>
<%= f.text_field :chat_screen_name %>
<p>
  <%= f.submit 'Update' %>
</p>
<% end %>

and then this to the Robot controller in the show action:

@recipient = Recipient.new
  @recipients = Recipient.all

Alas, I'm still getting a NoMethod error that says: "undefined method `recipient' for #"

I'm not sure what I'm missing. Any help would be greatly appreciated.

Thank you.

© Stack Overflow or respective owner

Related posts about ruby-on-rails