Skip to content

Commit

Permalink
Demos link params and handling in template or controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kinseyost committed Sep 14, 2016
1 parent 6863354 commit f4730db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/controllers/demo_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ class DemoController < ApplicationController
layout false

def index
render(:template => 'demo/index')
end
def hello
@array = [1, 2, 3, 4, 5]
@id = params['id']
@name = params['name']
@page = params['page']
render(:template => 'demo/hello')
end
def somethingRandom
Expand Down
14 changes: 11 additions & 3 deletions app/views/demo/hello.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
<br/>
<% target = "Kinsey" %>
<%= "Hello, my name is #{target}" %>

<% 2.times do %>
<%= "xxx" %>
<% end %>
<% end %><br/>

<% @array.each do |n| %>
<%= n %>
<% end %>
<% end %><br/>

<%= link_to('Ruby Link', {:action => 'somethingRandom'}) %><br/>

<%= link_to('Ruby Link', {:action => 'somethingRandom'}) %>
id from params: <%= params['id'] %><br/>
id from @instance: <%= @id %><br/>
name: <%= @name %><br/>
page: <%= @page %><br/>
next page: <%= @page.to_i + 1 %><br/>
Inspect Params <%= params.inspect %>
10 changes: 9 additions & 1 deletion app/views/demo/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<h1>Demo#index</h1>
<p>Find me in app/views/demo/index.html.erb using </p>
<%= link_to("#{@actionName}", {:action => @actionName}) %>
<%= link_to("#{@actionName}", { :action => @actionName }) %>
<%= link_to("Hello Page", { :action => 'index' }) %>
<%= link_to("parameterized link", {
:action => 'hello',
:id => '14',
:name => 'kinsey',
:page => 1
})
%>

0 comments on commit f4730db

Please sign in to comment.