Vote count:
0
I have a Opportunity Model that has many Links. Links is a nested resource of Opportunity. On my views/opportunities/show.html.erb page, I display all the links that belong to that opportunity and I rendered a "new link" form as well. This form worked fine until recently and I am not sure why. When I fill out the "new link" form and click "add", the record does not save. Could someone please help me with this?
Here is my views/opportunities/show.html.erb page:
<%= render @opportunity %>
<form>
<fieldset>
<legend>Links</legend>
<div id="links">
<%= render @opportunity.links %>
</div>
<%= render :file => 'links/new' %>
</fieldset>
</form>
Here is my views/links/new page:
<div class="field">
<%= f.label "Description:" %> <br />
<%= f.text_field :description %>
</div>
<div class="field">
<%= f.label "URL:" %> <br />
<%= f.text_field :link_url %>
</div>
<div class="actions">
<%= f.submit 'Add' %>
</div>
<% end %>
Here is my create link controller:
def create
@opportunity = Opportunity.find(params[:opportunity_id])
@link = @opportunity.links.new(link_params)
if @link.save
redirect_to @opportunity, notice: 'link has been added'
else
redirect_to @opportunity, alert: 'Unable to add link'
end
end
Here is the code from my console:
Started GET "/opportunities/7?utf8=%E2%9C%93&authenticity_token=ZLgPz98w2MjTChzzDXJ8EcqNmYNtBUG5DSYcp1CXReU%3D&link%5Bdescription%5D=testlink&link%5Blink_url%5D=testlink&commit=Add" for 127.0.0.1 at 2014-06-02 15:19:06 -0400 Processing by OpportunitiesController#show as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZLgPz98w2MjTChzzDXJ8EcqNmYNtBUG5DSYcp1CXReU=", "link"=>{"description"=>"testlink", "link_url"=>"testlink"}, "commit"=>"Add", "id"=>"7"} Opportunity Load (0.2ms) SELECT "opportunities".* FROM "opportunities" WHERE "opportunities"."id" = ? LIMIT 1 [["id", 7]] Rendered opportunities/_opportunity.html.erb (2.0ms) Link Load (0.1ms) SELECT "links".* FROM "links" WHERE "links"."opportunity_id" = ? [["opportunity_id", 7]] Rendered links/_link.html.erb (0.2ms) Rendered links/new.html.erb (2.0ms)
Aucun commentaire:
Enregistrer un commentaire