Best way to customize sharetribe

Hi folks,

I’m trying to customize sharetribe and was wondering what the best way to do so was? Is it best to just dive in and modify the core code? Use an engine? Some other path?

I’m interested in, for example:

  • modifying the views to look different (beyond CSS styling)
  • adding attributes to models (like the person model)
  • adding new controllers

I know that adding more customizability is one of the items on the roadmap, but was wondering what the best path forward was at present.

I was able to use deface to modify a view pretty easily, but was wondering about model changes.

Any guidance would be appreciated.

3 Likes

My guess is that most people are just doing the good 'ol modify the code and resolve conflicts when pulling the upstream updates. But that is definitely a problematic path to take.

Instead of adding attributes to the model, it might be better to add a new model and just use the person_id as a foreign key to link the to models. That way your own additions are more isolated and not that prone to conflicts with the upstream changes.

For the same reason, I’d also give a try for Rails engines. I haven’t used engines in any real life work, so I’m not an expert, but they seem to give the desired isolation for your own changes. To my understanding you can also add your own controllers to an engine and then mount it to the host application in the routes.rb file.

If you end up trying engines, let me know how it goes! I’m super interested to hear!

1 Like

I am going to try the rails engine route and found this book to be helpful: http://modular-rails.samurails.com/

2 Likes

And, actually just gave up on using an engine to modify share tribe. From what I can figure out, it looks like engines are great for adding new functionality to an app, but aren’t as good for modifying existing functionality.

In particular I got stuck on integrating with the share tribe view and the application helper when using an engine with isolate_namespace.

At this point I am just using the “add it to the main codebase and merge from upstream regularly” approach.

Best of luck to anyone else trying this, and please let me know if you get it to work.

2 Likes

And one more useful link if you want to use any engines but still leverage the sharetribe UI: http://candland.net/2012/04/17/rails-routes-used-in-an-isolated-engine/

1 Like

Hello sharetribe community,

I hope this conversation is not too old, but I’m thinking about the same problem at the moment. I’m a RoR developer starting to use sharetribe. I’m also wondering what the best way is to add / change functionality without touching the core code.

From other projects, where gems like spree commerce and refinerycms were used, I was used to write decorators for classes to add or change code. Therefor a few lines of code were added to config/application.rb:

config.to_prepare do
  # Load application's model / class decorators
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
    Rails.configuration.cache_classes ? require(c) : load(c)
  end

  # Deface: https://github.com/spree/deface
  # Load application's view overrides
  Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
    Rails.configuration.cache_classes ? require(c) : load(c)
  end
end

A Decorator would look like this:

# app/model/booking_decorator.rb
Booking.class_eval do
    # Add custom code here
end

There was no need to touch original files. We would add a new file to our branch per changed class. Did anyone try this out? What are your thoughts about it?

Cheers, Georg

1 Like

Hi Georg,

I ended up customizing sharetribe pretty heavily. I think that decorators work really well, and also created a few ruby services (plain old ruby objects) that my decorators could call.

For views, I ended up hacking the view, or creating a partial if that worked better.

Here’s a blog post I wrote that covers some of what I did: http://www.mooreds.com/wordpress/archives/2208

Note I still haven’t merged in upstream sharetribe yet; when I do I may rue some of the choices.

2 Likes

Hi Dan,

thanks for your thoughts. Lets see how the magic will work after fetching updated code… :wink: but for me it sounds like a good idea.

I need to try it out. I’m even not sure, if the code above works within sharetribe. Other gems were loaded as engines. Is there a difference in the config file? I think timing is important, when it comes to loading _decorator files.

Is there anybody else trying to conquer this problem?

Cheers, Georg

I can tell you that the decorator code as written in that blog posts works for app.thefoodcorridor.com :smile:

I’m using one other engine for scheduling software, and have decorators layered over that code too.

Good luck.

1 Like

Hello Sharetribe Community,

As this topic is really old, I am wondering is the mentioned way to customize Sharetribe are still consider as the best the community as found today or if more appropriate guidance have been found. Could you please share what would be your final guide for customization.

@mooredsb I have also been reading your post on your blog which I found easy to understand thanks for that.

@rap1ds Is there an official guidance provided by the Sharetribe CORE to enhance the app and to customize models and views

Thanks in advance