Reputation: 1129
Hi guys in my index view page, i'm having this error in this line :
<td id="change"><%= link_to 'Analyze',user_generator_path(current_user.generators)%></td>
The code for that line is :
<% if generator.result.present?%>
<td> <%= generator.result.ncbi_ref_seq %></td>
<td> <%= generator.result.genome_sample %></td>
<td align="center"><%= generator.result.binding_times %></td>
<td id="change"></td>
<td id="change"><%= link_to 'Delete', generator, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% else %>
<td></td>
<td></td>
<td></td>
<td id="change"><%= link_to 'Analyze',user_generator_path(current_user.generators)%></td>
<td id="change"><%= link_to 'Delete', generator, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>
I'm getting
No route matches {:action=>"show", :controller=>"generators", :user_id=>#<ActiveRecord::Associations::CollectionProxy [#<Generator id: 1, primer_length: 20, no_A: nil, no_T: nil, no_G: nil, no_C: nil, melting_temp: nil, choice: nil, random_primer_generated: nil, user_seq: nil, f_primer: nil, r_primer: nil, result_choice: nil, user_id: 1, created_at: "2013-12-09 09:27:39", updated_at: "2013-12-09 09:27:39">]>, :id=>nil, :format=>nil} missing required keys: [:id]
Generator.rb
def new
@generator = current_user.generators.build(params[:generator])
end
def create
@generator = current_user.generators.build(params[:generator])
@generator.user_id = current_user.id if current_user
@generator.choice = params[:choice]
if params[:choice] == 'Randomly'
@generator.random_generate(generator_params)
elsif params[:choice] == 'Specified ATGC'
@generator.specified_ATGC(params[:no_A],params[:no_T],params[:no_G],params[:no_C])
elsif params[:choice] == 'Seating'
@generator.seating(params[:user_seq])
end
@generator.result_choice=params[:result_choice]
@generator.save
respond_to do |format|
if @generator.result_choice == 'Yes'
format.html { redirect_to(user_generator_path(@generator)) }
else
format.html { redirect_to(user_generators_path(@generator) ) }
end
end
end
How do i fix it ? i just want to display user's generators. if there's result, then user.generators.result
Route.rb
root :to => 'welcome#index'
get '/auth/:provider/callback' => 'sessions#create'
post '/auth/identity/callback' => 'sessions#create'
resources :users do
resources :generators
resources :results
end
resources :identities
Upvotes: 0
Views: 826
Reputation: 76784
To me, it looks like this is the culprit:
:id=>nil
We've had this problem with nested routes before (where you have /users/15/articles/215/edit
)
This is an immediate fix:
user_generator_path(:user_id => current_user.generators, :id => variable_here)
However, it seems there is a deeper issue with your system, namely that you've created what seems to be a member route, which needs an id
parameter to get it working correctly
Systemic Fix
You mention you "just want to display user's generators", which would make an index
collection route for the user's generators
?
The way to display this is to firstly change the link to open the index
action of the generators
controller. Currently, your controller shows you're either loading the new
or create
actions, and your error pertains to opening the show
action. The show action in particular requires the id
of the item, which is where this error is coming form
From the sounds of it, I'd just route to the index
path for users_generators_path
. There you can display the generators for the user without a requirement for the specific id
Upvotes: 1