I recently created a gem to aid in building and rendering a monthly calendar. The API is much less magical than the table_builder gem, with all the same features. Check it out at https://github.com/austinthecoder/cal. I hope it helps.
I followed these directions exactly but when I visit http://[ip] I get "Not Found: /". However, when I visit http://[ip]/[appname] it hits the app. Is it possible one of the paths in one of the configs is wrong?
I agree with @Dom. Nothing wrong, just different use cases.
For the non-db backed, basic approach I'd make my route a singular resource
ruby
resource :search
The controller could just about stay the same, except for the show action:
ruby
defshow@search = Search.last
end
And then the model could be something like:
ruby
classSearchclass << selfdefcreate!(attrs = {})
new(attrs).save!
enddeflast# retrieve the attrs from storage
new(attrs)
endenddefinitialize(attrs = {})
@attrs = attrs
enddefkeywords@attrs[:keywords]
enddefsave!# store the attrs somewhere# maybe serialized in the session, or in mongo or memcachedendend
By "non-db backed" I mean you don't have to store every search, but you'd still need some type of storage. It's possible not to use storage by showing the search from the create action, but I think it's good practice to only display pages from a GET request.
It is much cleaner, but we can take it a little further. If we change the present method to:
ruby
defpresent(object, klass = nil, &block)
klass ||= "#{object.class}Presenter".constantize
presenter = klass.new(object, self)
if block_given?
block.arity > 0 ? yield(presenter) : presenter.instance_eval(&block)
end
presenter
end
We can slim our view down to:
html
<% present @user do %><divid="profile"><%= avatar %><h1><%= linked_name %></h1><dl><dt>Username:</dt><dd><%= username %></dd>
...
<% end %>
We'll still have access to the template via h, just need to make it a public method.
I recently created a gem to aid in building and rendering a monthly calendar. The API is much less magical than the table_builder gem, with all the same features. Check it out at https://github.com/austinthecoder/cal. I hope it helps.
Well, turns out the rackup file was tampered with! :-/
Ryan,
I followed these directions exactly but when I visit http://[ip] I get "Not Found: /". However, when I visit http://[ip]/[appname] it hits the app. Is it possible one of the paths in one of the configs is wrong?
While it's fresh in my brain, here's an example for using the session.
Controller:
Model:
There's probably ways to make this cleaner, but I think the idea is there.
I agree with @Dom. Nothing wrong, just different use cases.
For the non-db backed, basic approach I'd make my route a singular resource
resource :search
The controller could just about stay the same, except for the
show
action:And then the model could be something like:
By "non-db backed" I mean you don't have to store every search, but you'd still need some type of storage. It's possible not to use storage by showing the search from the
create
action, but I think it's good practice to only display pages from a GET request.I've been doing:
I like your way better, although I wish this was possible:
It is much cleaner, but we can take it a little further. If we change the
present
method to:We can slim our view down to:
We'll still have access to the template via
h
, just need to make it a public method.What's the best way to test a decorator? More specifically, how would you test the following method (in rspec):
When I try the following, I get
undefined method 'number_to_currency' for nil:NilClass
:There's must be some magic going on that sets the view context somewhere. Anyone write decorator helpers for rspec yet?