Topic: Beginner - Calling a partial as a link

I have two databases, cities and venues. I have created the new.html.rb venue page as a partial in the cities view directory as _new_venue.html.rb. the venue database has city_id as an attribute, this will be used to relate venues to their related city.

This partial is then called in the cities show.html.rb as;

<%= render :partial=>"new_venue", :locals=>{:venue=>Venue.new(:city_id=>@city.id)} %>

this means that the city id is already filled in with the related city id to reduce errors.

I'm trying to change it so the partial is a link rather than displayed in the show.html.rb. So the user clicks the link and the partial is displayed with the right city_id already filled in.

Thanks in advance.

Re: Beginner - Calling a partial as a link

Thanks for the reply, not sure if its relevent though...

Re: Beginner - Calling a partial as a link

Not sure right no, but try this:

  <%= render new_venue, :city_id => @ city_id %>

or that

  <%= render "new_venue", :city_id => @ city_id %>

Re: Beginner - Calling a partial as a link

Thnks for your help, but it returns the error message:

NoMethodError in Cities#show

Showing /home/matt/student/app/views/cities/_new_venue.html.erb where line #3 raised:

undefined method `model_name' for NilClass:Class

Extracted source (around line #3):

1: <h1>New venue</h1>
2:
3: <%= form_for(@venue) do |f| %>
4:   
5:   <div class="field">
6:     <%= f.label :city_id %><br />

Re: Beginner - Calling a partial as a link

does that path even exist?
you should make a venue controller and put all the stuff related to it inside it, and add it to your routes, if you want to add venues when creating a city, the use nested resources