Skip to content

Cleaning up syntax #34

@gorn

Description

@gorn

I like Cells gem for Rails very much, the only thing I do not like it the syntax. For example I find

cell(:post,post).(:title_with_date)

very ugly. I respect, that the author has his own syntac preference, I just want to be able to make it more rubyish for my purposes. Alternative syntax

PostCell.(post).(:title_with_date)

is slightly better, but I would prefer something like

post.cell.title_with_date

or at least post.cell(:title_with_date). I tried to implement this in possibly very naive way:

class Post < ActiveRecord::Base
  ...
  def cell(method_symbol)
    PostCell.(self).(method_symbol)
  end
end

it works quite well for "not so comlicated" methods, however when I use it on cell method link_to_title which looks like this

class PostCell < Cell::ViewModel
  ...
  def link_to_title
    link_to model.title, model
  end
end

it fails with

undefined method `[]' for nil:NilClass
on line 58 of the gem code https://github.com/trailblazer/cells-rails/blob/master/lib/cell/rails.rb#L58

It seems to be missing some part of the context, but I do not know how to make it happy :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions