I have a view with code:
<section>
<h1>
<%= render @client %>
</h1>
<h2>
<%= render @client.telnumbers %>
</h2>
<h3>
<%= link_to 'New Tel', new_telnumber_path, :locals => { :client => @client }, :remote => true %>
</h3>
</section>
But in my Telnumbers Controller - variable @client - nil What can I see my @client ?
My Telnumbers controller:
class TelnumbersController < ApplicationController
def new
@telnumber = Telnumber.new
@telnumber.client_id = @client.id
end
def create
@telnumber = Telnumber.new(params[:telnumber])
render :action => :new unless @telnumber.save
end
end
So I have Error Called id for nil ...
I solved it by adding variables into new_telnumber_path
<%= link_to 'New Tel', new_telnumber_path(:client_id => @client.id ), :remote => true, :class => 'btn btn-small' %>
And in Controller:
def new
@telnumber = Telnumber.new
@client = Client.find(params[:client_id])
@telnumber.client_id = @client.id
end
Thanks!