Skip to content

Instantly share code, notes, and snippets.

@px-amaac
Last active December 26, 2015 18:08
Show Gist options
  • Save px-amaac/7191770 to your computer and use it in GitHub Desktop.
Save px-amaac/7191770 to your computer and use it in GitHub Desktop.
<%= form_for([@digital_object_identifier, @url]) do |f| %>
<div class="field">
<%= f.text_field :url %>
</div>
<%= f.submit "Set New Url", class: "btn btn-success" %>
<% end %>
class DigitalObjectIdentifiersController < ApplicationController
before_action :set_digital_object_identifier, only: [:show, :edit, :update, :destroy]
def index
@digital_object_identifiers = DigitalObjectIdentifier.all
end
def show
@url = Url.new
end
private
# Use callbacks to share common setup or constraints between actions.
def set_digital_object_identifier
@digital_object_identifier = current_user.digital_object_identifiers.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def digital_object_identifier_params
params.require(:digital_object_identifier).permit(:string_identifier, :integer_identifier, :description, urls_attributes: [ :url ] )
end
def edit_digital_object_identifier_params
params.require(:digital_object_identifier).permit(:string_identifier, :integer_identifier, :description )
end
end
Started POST "/urls" for 127.0.0.1 at 2013-10-28 00:18:27 -0700
Processing by UrlsController#create as HTML
Parameters: {"utf8"=>"√", "authenticity_token"=>"Actwx4PzZoH2Zb3F2x1ZFKzTV/b2F
pFfTltkFBUHj2o=", "url"=>{"url"=>"wew.wew.wew"}, "commit"=>"Set New Url"}
←[1m←[36mUser Load (0.0ms)←[0m ←[1mSELECT "users".* FROM "users" WHERE "users
"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1←[0m
Completed 404 Not Found in 40ms
ActiveRecord::RecordNotFound (Couldn't find DigitalObjectIdentifier without an I
D):
app/controllers/urls_controller.rb:15:in `set_digital_object_identifier'
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"Actwx4PzZoH2Zb3F2x1ZFKzTV/b2FpFfTltkFBUHj2o=",
"url"=>{"url"=>"www.somethingnew.com"},
"commit"=>"Set New Url"}
DigitalObjecIdentifier::Application.routes.draw do
resources :digital_object_identifiers do
resources :urls, only: [:create]
end
devise_for :users
root :to => "digital_object_identifiers#index"
resources :users
end
<p>
<strong>URL:</strong>
<p>
www.asdkl.com
</p>
<p>
www.somethingnew.com
</p>
<p>
www.somethingelse.com
</p>
<p>
www.asdkj.com
</p>
<p>
</p>
</p>
<section>
<form accept-charset="UTF-8" action="/urls" class="new_url" id="new_url" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="Actwx4PzZoH2Zb3F2x1ZFKzTV/b2FpFfTltkFBUHj2o=" /></div>
<div class="field">
<input id="url_url" name="url[url]" type="text" />
</div>
<input class="btn btn-success" name="commit" type="submit" value="Set New Url" />
</form>
</section>
<a href="/digital_object_identifiers/7/edit">Edit</a> |
<a href="/digital_object_identifiers">Back</a>
<p id="notice"><%= notice %></p>
<p>
<strong>String identifier:</strong>
<%= @digital_object_identifier.string_identifier %>
</p>
<p>
<strong>Integer identifier:</strong>
<%= @digital_object_identifier.integer_identifier %>
</p>
<p>
<strong>Description:</strong>
<%= @digital_object_identifier.description %>
</p>
<p>
<strong>URL:</strong>
<% @digital_object_identifier.urls.each do |url| %>
<p>
<%= url.url %>
</p>
<% end %>
</p>
<section>
<%= render 'shared/url_form' %>
</section>
<%= link_to 'Edit', edit_digital_object_identifier_path(@digital_object_identifier) %> |
<%= link_to 'Back', digital_object_identifiers_path %>
class UrlsController < ApplicationController
before_action :set_digital_object_identifier
def create
@url = @digital_object_identifier.urls.build(params[:url])
if @url.save
flash[:success] = "Url Added"
redirect_to root_url
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_digital_object_identifier
@digital_object_identifier = current_user.digital_object_identifiers.find(params[:digital_object_identifier_id])
redirect_to root_url if @digital_object_identifier.nil?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment