trailblazer / cells Goto Github PK
View Code? Open in Web Editor NEWView components for Ruby and Rails.
Home Page: https://trailblazer.to/2.1/docs/cells.html
View components for Ruby and Rails.
Home Page: https://trailblazer.to/2.1/docs/cells.html
In cells 3.6.4 running rake test:cells
fails with the following message:
/tmp/cells-test/test/cells/comment_cell_test.rb:3:in `<top (required)>': uninitialized constant Cell::TestCase (NameError)
Stack trace does not show anything interesting (every line points at rake-0.9.2/lib/rake/rake_test_loader.rb:9
).
It happens even in a newly created rails app with nothing but a single cell. Happens with both cells 3.6.3 and 3.6.4 but not 3.6.2. Tested with ruby 1.9.2-p290, rails 3.1.0.rc5.
To reproduce:
rails new cells-test
gem 'cells', '>= 3.6.3'
somewhere in Gemfilebundle install
rails g cell Comment display
rake test:cells
Also when I start irb
and type
require 'cells'
I get
NameError: uninitialized constant Cell::Rails::ActionController
I seem to be having a rather strange issue with nested resources. If i link to a child resource (example: link_to "New Store", :controller => "stores", :action => "new") from a cell being rendered by said child resource, i get an error saying the route can't be found. If i take that same link_to and cut/paste it directly into the page, it works fine. (paths work the same way.)
if i do a rake routes i can confirm the route is there.
Is there a workaround for this?
Hi,
I keep getting these deprection warnings:
DEPRECATION WARNING: @options is deprecated! Call options.[] instead of @options.[]. Args: [:char].
It's not clear to me, how to avoid them. I've tried to call a method opts inststead of the variable @opts, but that didn't work.
What am I missing?
Greetings
Michael Kastner
uninitialized constant CommentsCell
Extracted source (around line #122):
119: <% end %>
120:
121:
E:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in const_missing' E:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/inflector.rb:361:in
constantize'
E:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/inflector.rb:360:in each' E:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/inflector.rb:360:in
constantize'
E:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/string/inflections.rb:162:in constantize' D:/work/ongoup/vendor/plugins/cells/lib/cell/base.rb:320:in
class_from_cell_name'
D:/work/ongoup/vendor/plugins/cells/lib/cell/base.rb:360:in create_cell_for' D:/work/ongoup/vendor/plugins/cells/lib/rails_extensions.rb:30:in
render_cell'
D:/work/ongoup/app/views/wiki/articles/show.html.erb:122:in _run_erb_app47views47wiki47articles47show46html46erb' D:/work/ongoup/app/controllers/wiki/articles_controller.rb:36:in
index'
I was turn on the threadsafe in the environments/production.rb
Given this sweeper:
class UserSweeper < ActionController::Caching::Sweeper
observe User
def after_update(user)
Rails.logger.debug Rails.cache.instance_variable_get(:@data).keys.inspect
expire_cell_state HeaderCell, :show
Rails.logger.debug Rails.cache.instance_variable_get(:@data).keys.inspect
end
end
when #after_update
is called the HeaderCell
cache key isn't being deleted as expected. No errors are raised.
Firing up the debugger reveals that we are hitting ActionController::Caching::Sweeping#method_missing
with @controller
equal to nil
and so being silently returned.
A simple include Cells::Rails::ActionController
in the Sweeper fixes this but I'm left wondering why it's not being properly mixed in without this.
ree-1.8.7-2011.03, rails 3.0.9, cells 3.6.4.
Hi,
after some times I'm retrying to use Rails cells...
The first cell I've created contains some logic to present flash messages (flash[:notice] / flash[:alert]) using jquery with fancybox but seems that flash object cannot be accessed from cell:
undefined method `flash' for #CommonCell:0xa656ecc
Extracted source (around line #1):
1: <% if flash[:notice] || flash[:alert] -%>
2: <script type="text/javascript">
3: $(document).ready(function(){
4: message = ""
Is there any workaround to access flash object from cell ?
Many thanks.
I'm using Rails 2.3.x with my project configured for Bundler support. I added gem 'cells'
and ran rvm exec bundle install
. Firstly it incorrectly installed cells 3.4.2 even though the Gemfile requires Rails 3.0.0. I'm not sure whether that's an issue with cells or Bundler. Anyway, I fixed it to gem 'cells', '~> 3.3.5'
, and got the version compatible with Rails 2.3.x, but the generator didn't work:
$ rvm ruby ./script/generate cell
Couldn't find 'cell' generator
even though this file exists:
/usr/local/rvm/gems/ruby-1.8.7-p302/gems/cells-3.3.5/rails_generators/cell/cell_generator.rb
So I'm stuck on square one :-(
Hi,
Many compliments for the great cells plugins !
I'm having a strange performance problem using render_cell.
My application is running on Rails 2.3.2/2.3.3 - Ruby 1.8.7 patch level 72 with MySQL db and below I show you what happens rendering 48 cells (only one has db access):
running under mongrel development (script/server -e development) I have this results
696 msec View: 441 Db: 24
running under mongrel production (script/server -e production) I have this results
4352 msec View: 4293 Db: 35
The problem is clearly on view processing...
If I try to put the application in production under passenger 2.2.4 I have the same performance problem.
I've tried to transform some calls from render_cell to render :partial and the performance problem has gone away.
I don't want to return to partial or render_component, can you help me with this strange behaviour ?
I have noticed that instance variables in cells are overridden
by those in the controllers of the same name while the cell is
being rendered from the template (although the variables in the cell
are used if the cell method returns string directly). Is this
the intended behavior? I think it would be better the
variables defined in cells are on the top.
The patch attached will make it so.
diff --git a/lib/cell/base.rb b/lib/cell/base.rb
index 26720b0..6f7ea95 100755
--- a/lib/cell/base.rb
+++ b/lib/cell/base.rb
@@ -195,7 +195,9 @@ module Cell
def render_view_for_state(state)
### DISCUSS: create Cell::View directly? are there still problematic class vars in View::Base
view_class = Class.new(Cell::View)
- action_view = view_class.new(@@view_paths, {}, @controller)
+ controller = @controller.dup
+ clone_ivars_to(controller)
+ action_view = view_class.new(@@view_paths, {}, controller)
action_view.cell = self
### FIXME/DISCUSS:
action_view.template_format = :html # otherwise it's set to :js in AJAX context!
C:\projects\dmh>ruby script\generate cell TeaserBoxes become_a_merchant newsletter
create app/cells/
create app/cells/teaser_boxes
create test/cells
create app/cells/teaser_boxes_cell.rb
undefined local variable or method `class_name' for #<CellGenerator:0x6123378>
ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32]
cells (3.3.5)
rails (2.3.8)
The cell and the folder named after the cell stays empty.
Greets,
Christian
I'm just getting into cells and am really liking them but I'm having some issues with tests:
I have a PageCell with a :footer
state which takes a single args
parameter. On a call to invoke(:footer, :foo => 'bar')
my code is throwing an unexpected ArgumentError: wrong number of arguments (0 for 1)
exception.
I've just cloned the repo to try and get to the bottom of it, but running the gem's tests is resulting in a load of failing tests too, mostly NameError: uncaught throw 'invalid_test'
.
Hello,
I got an error using cell with Rails3 RC. It used to work fine with Rails3 beta 4.
Now I get this error :
ActionView::Template::Error (undefined method `returning' for #NavigationCell:0x2ffc920):
7:
8: - content_for :sidenav do
9: = render_cell :navigation, :tree, :type => :product, :cache_name => "product_simple"
Full gist here : http://gist.github.com/493733
Does anybody have this error too ?
Thank you !
I am using cells 3.5.5, Ruby 1.9.2p0, and Rails 3.0.4
Anytime I try to render :nothing
, I get this error:
Template is missing
Missing layout layouts/insights with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/project/app/views", etc.
The fix for me has been render :text => ''
, but that feels dirty.
Using Rails 3.0.3 and the latest version of cells.
The following HAML is breaking the view:
With the error:
undefined method `user_path' for Cell::Rails::View
Is there some special way to get these url_helpers into Cells views?
Or am I missing something?
One of the things that interests me about using cells is that it offers better testing capabilities. I'd love to be able to use autotest with cells and I'm wondering if anyone can help.
Here's what I have so far in .autotest:
Autotest.add_hook :initialize do |autotest| autotest.add_mapping(/^app\/cells\/(.*)_cell\.rb$/) { |filename, _| filename } autotest.add_mapping(/^app\/cells\/(.*)_cell\.rb$/) { |_, m| ["test/cells/#{m[1]}_test.rb"] } end
Can anyone help ?
we've a app use subdomain-fu
the following raise error @request is nil
<%= link_to 'New', new_sth_url(:subdomain => 'sth') %>
Hi,
I have a rails app with your great cells gem, with ENV['RAILS_RELATIVE_URL_ROOT'] set.
While upgrading in rails 3, I noticed that all link_to rendered from cell views miss the relative path.
It appears that :script_name option doesn't get propagated as it happens in standard views.
Can you check if it is a bug or I'm missing sth?
...this needs to work for sure to get cells to replace partials as stated in the readme. Or is there any way to enable it?
We should limit it to require the parts of Rails that it actually needs.
Cells in its Railtie wants its initializers to be executed after :set_routes_preloader. I think this is a bad idea since Finisher is expected to run last. Its :finisher_hook executes :after_initialize hooks and many of them assume that initialization has already been performed. While Rails does not prevent you from doing this it was probably not expected - it causes :finisher_hook to be pushed too far down in initialization order and makes asset precompilation fail.
I think that Cells' initializers should be converted into :after_initialization hooks.
See the following links for more details:
Rails issue #1587: after_initialize hooks sometimes get executed during initialization
Rails pull request #1602: Do not TSort Finisher and Bootstrap initializers
kindly, is Cells supports Rails 3 or there is plans to support it.
Any ideas what's going on here?
test_select_list_with_selection(ContactCellTest): ActionView::TemplateError: undefined method `rewrite' for nil:NilClass On line #16 of app/cells/contact/select_list.html.erb 13: end 14: %> 15: 16: <%= url_for(:controller => 'projects', :action => 'invoice') %> 17: 18: 19: >- app/cells/contact/select_list.html.erb:16 app/cells/contact_cell.rb:32:in `select_list' /test/cells/contact_cell_test.rb:42:in `test_select_list_with_selection' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `run_suite' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in `start_mediator' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in `start' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit.rb:278 -e:2
As it can be seen at https://github.com/apotonick/cells_examples/blob/master/app/cells/newsletter_cell.rb (I couldn't find any other example for processing forms in cells), it is suggested to use one cell for both "new" and "create" actions, however there at least 2 issues with this way:
Let's imagine we have "new comment" cell (with actual form) embedded under blog post. Once user submits form:
Inside application controller I have some methods that I use site-wide, some of them exported as helpers with helper_method.
Those helpers are not available inside cells.
PS: I know you hate helpers btw :)
I need to render a cell outside of a controller but it fails due to ActionView calling delegated methods that don't really exist. This patch (and the subsequent test case) fix the problem.
patch: 79aa612
From https://github.com/apotonick/cells/wiki/Troubleshooting
I tried adding this initialiser but I get an error from line 7 of actionpack-3.0.3/lib/action_view/paths.rb:
can't modify frozen array
It seems that Cell::Base.view_paths is no longer an array but a ActionView::PathSet object.
If it helps, I'm actually trying to use cells within a gem (I'm breaking a complex application in to gems so we can build new sites from those parts) - but neither an initializer block in the Gem/Engine works nor an a initializer file within the main app.
Any ideas?
Render cells throws an exception.
Wrong number of arguements (1 for 0)
The version of rails is 3.0.5 and the GEM version is 3.6.2
Anyway we can add a route to render a cell action?
With rails 3's fancy new routing features, maybe something like:
match 'components/basket' => BasketCell.action(:index)
The reason i would want to do this is to either load the component using Ajax, or move the caching to Varnish or something.
Hoping cells would provide incredibly light controller actions that generate small amounts of html components which can be accessed by Varnish and cached at the edge proxies.
Hi,
Seems like the github repo has :
s.add_dependency "actionpack", "~> 3.0"
s.add_dependency "railties", "~> 3.0"
but the gem has :
s.add_dependency "actionpack", "~> 3.0.0"
s.add_dependency "railties", "~> 3.0.0"
content_for does not do the job
...which we discussed already: I think seamless support for this it's really needed.
As encouraged by Rails-Core developers, upgrade to latest version of Rails 2.3 was recommended.
Once I've upgraded, application started to show the following warning:
DEPRECATION WARNING: ActiveSupport::Dependencies.load_paths is deprecated, please use autoload_paths instead. (called from evaluate_init_rb at /Users/luis/.rvm/gems/ruby-1.8.7-p330@krrb/gems/cells-3.3.5/rails/init.rb:8)
https://github.com/apotonick/cells/blob/rails-2.3/rails/init.rb#L8
That is because load_paths is now called autoload_paths
Checking for ActiveSupport::Dependencies.respond_to?(:autoload_paths)
can provide a working solution for both newer and older Rails versions.
Thank you.
$ rails g cell Opinion display --haml
create app/cells/opinion_cell.rb
invoke erb
create app/cells/opinion/display.html.erb
invoke rspec
create spec/cells/opinion_cell_spec.rb
The .erb file created is the standard one:
cat app/cells/opinion/display.html.erb
<p>
Find me in app/cells/opinion/display.html.erb
</p
This is becoming a very good best practice for Ruby projects now, and it very much makes sense to ensure libs works with all rubies. Adding this is a matter of adding a YAML-file to the root and sign up at travis-ci.org, so I really suggest to do this to ensure quality of Cells gem. :)
cheers
Hi there, I'm getting the following deprecation warnings as per the title of this issue:
DEPRECATION WARNING: ActiveSupport::Dependencies.load_paths is deprecated, please use autoload_paths instead. (called from evaluate_init_rb at /ree-1.8.7-2011.03@/gems/cells-3.3.5/rails/init.rb:19)
DEPRECATION WARNING: ActiveSupport::Dependencies.load_once_paths is deprecated and removed in Rails 3, please use autoload_once_paths instead. (called from evaluate_init_rb at /ree-1.8.7-2011.03@/gems/cells-3.3.5/rails/init.rb:23)
I've removed paths specific to my app from the above just in case they look funny :)
Is it possible to regress this back to the 3.3 branch?
rails g cell
says :
rails g cell main_menu display sort -e haml -t rspec
...
Spec:
spec/cells/main_menu_cell_spec.rb
but :
$ rails g cell main_menu display sort -e haml -t rspec
create app/cells/main_menu_cell.rb
invoke haml
create app/cells/main_menu/display.html.haml
create app/cells/main_menu/sort.html.haml
error rspec [not found]
Hi,
I am using Devise as authentication plugin. Since login box is common
across all my pages, I have extracted that out as a cell. However, I
am getting errors while accessing devise helper methods such as
user_signed_in? etc. It is giving me undefined method error. Based on
the last post, I tried inserting "include
Devise::Controllers::Helpers". It still is giving me errors.
Here's the cell controller and the view code
app/cells/authenticate_cell.rb
class AuthenticateCell < Cell::Rails
include Devise::Controllers::Helpers
def login
@user = User.new
render
end
end
app/cells/authenticate/login.html.rb
<div class="container login_info">
<% if user_signed_in? %>
Signed in as <%= current_user.email %>. Not you?
<%= link_to "Sign out", destroy_user_session_path %>
<% else %>
<%= form_for(resource, :as => resource_name, :url =>
session_path(resource_name)) do |f| %>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<p><%= f.label :password %><br />
<%= f.password_field :password %></p>
<% if devise_mapping.rememberable? -%>
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></
p>
<% end -%>
<p><%= f.submit "Sign in" %></p>
<% end %>
<% end %>
</div>
Thanks in advance.
hello guys. I'm moving my first steps in cells because we decided to use it in our next project at work. I have defined a basic layout in app/cells/layouts/main_cell.html.erb
. When I pick the layout from the render method it works, but when I call the layout class method it doesn't. Is this intended?
Here is an explanatory example:
class NewsCell < Cell::Rails
layout "main_cell"
def spotlight
render :layout => "main_cell" # renders with the correct layout
end
def more_news
render # doesn't render the correct cell layout
end
end
I'm using Rails3.1 with Cells 3.6.2.
Thank you for your time.
In Application-controller:
helper_method :current_account
In cell:
class LayoutCell < Cell::Base helper :layout, :navigation # helper_method :current_account # don't seem to affect the error def header render end def footer render end end
The error:
undefined method `current_account' for #
When I use image_tag in a cell view I've "can't convert nil into String" error
What is weird is the following code is working
=image_tag("http://dummyimage.com/32x32/bb9d77/fff.png&text=Thumb")
but that one is not working
=image_tag("default/missing_xsmall.png")
However using the exact same code in a rails view is working. Am I missing something ?
Any plans to gemify?
Sorry Nick, don't know how I missed the message but you've still got:
"Gemfile.lock", "test/dummy/tmp"
in the Gemspec.
I am migrating a development site to a staging server and upgraded to cells 3.3.4. Now I am getting this error: "Missing template design/top.erb in view path app/cells:app/cells/layouts"
There have been no changes to the (relative) file locations but it appears from the stack trace that this file (top.html.erb) can't be found now.
Any thoughts?
I got this error:
wrong number of arguments (1 for 0)
<%= render_cell :shared, :menu %>
vendor/bundle/ruby/1.8/gems/actionpack-3.0.9/lib/abstract_controller/rendering.rb:74:in initialize' vendor/bundle/ruby/1.8/gems/actionpack-3.0.9/lib/abstract_controller/rendering.rb:74:in
initialize'
vendor/bundle/ruby/1.8/gems/actionpack-3.0.9/lib/abstract_controller/layouts.rb:299:in initialize' vendor/bundle/ruby/1.8/gems/cells-3.6.3/lib/cell/rails.rb:53:in
initialize'
vendor/bundle/ruby/1.8/gems/cells-3.6.3/lib/cell.rb:28:in new' vendor/bundle/ruby/1.8/gems/cells-3.6.3/lib/cell.rb:28:in
create_cell_for'
vendor/bundle/ruby/1.8/gems/cells-3.6.3/lib/cell.rb:18:in render_cell_for' vendor/bundle/ruby/1.8/gems/cells-3.6.3/lib/cells/rails.rb:53:in
render_cell'
My fix:
In file "lib/cell/rails.rb" replace line "super" to "super *args":
def initialize(parent_controller, *args)
super *args
@parent_controller = parent_controller
setup_backwardibility(*args)
end
thanks.
In controller class if a before filter renders or redirects, the action will not run. However it doesn't work the same for cells.
Following code should render "filter", and renders "cell"
class SamleCell < Cell::Rails
before_filter :test5
def sample
render :text => "cell"
end
private
def test5
render :text => "filter"
end
end
Tested in rails3.
"test/dummy/tmp/test/cells/blog_cell_test.rb", "test/dummy/tmp/app/cells/blog_cell.rb"
Hey, I've been trying to get Cells to render a menu that links to a list of sub-domains.
I have gone through @wingrunr21's recent pull request for adding the UrlFor module, but I'm unsure how one should go about getting this working.
My cell looks like this:
class MenuCell < Cell::Rails
include ActionController::UrlFor
include UrlHelper
def primary
render
end
end
But I have also tried this method too:
module UrlHelper
def with_subdomain( subdomain )
subdomain = ( subdomain || '' )
subdomain += '.' unless subdomain.empty?
[subdomain, request.domain, request.port_string].join
end
def url_for( options = nil )
if options.kind_of?( Hash ) && options.has_key?( :subdomain )
options[:host] = with_subdomain( options.delete( :subdomain ) )
end
super
end
end
module Cell
class Rails < AbstractController::Base
include ActionController::UrlFor
include UrlHelper
end
end
Ideally I think Cells should be able to handle a link_to call like this:
%li= link_to mod.name, root_url { :subdomain => mod.subdomain }
Do you know what needs to be done here?
I'm not sure if this is by design or not but I was expecting that when caching is configured for a cell, that details of cache hits, misses and deletions would be written to the log file (at least in development).
Is this something that is broken, intentionally missing or just as yet, not implemented and would be accepted as a patch?
Looks to me like maybe the initialize function in base methods forgot to grab controller before options
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.