Ruby on Rails Friday, January 26, 2018

Right. It's even easier for a gem. Just put your templates in the same relative place within your normal rails views or controllers, properly named, and they will "shadow" the version within the gem. In most things in Rails, "nearest wins". Gems insert their code into the Rails lookup path *after* the core application code, not before. So if you add code to the core, it will be found before the gem's code is, and Rails will stop looking at that point.

I just dealt with this last night, when I overrode the Thredded gem to make the breadcrumbs work the way I needed them to. All I had to do was add this folder:

app/views/thredded/shared

and add the _breadcrumbs.html.erb file to that folder, and I had complete control over that one file (without needing to shadow every other part of the gem).

Walter

> On Jan 26, 2018, at 7:10 AM, Mauro Locatelli <crivotz@gmail.com> wrote:
>
> Sorry I've seen now the word 'gems'
> My instructions are to make override of scaffold generator.
>
> Mauro
>
>
> 2018-01-26 13:06 GMT+01:00 Mauro Locatelli <crivotz@gmail.com>:
> Yes, you can
>
> Model
> project_folder/lib/templates/active_record/model/model.rb
>
> Controller
> project_folder/lib/templates/rails/scaffold_controller/controller.rb
>
> Views
> project_folder/lib/templates/erb/scaffold/
>
> All the original file can be founded inside railties folder (bundle show railties)
> You can also add views editing scaffold_generator.rb
>
> Cheers
> Mauro
>
> 2018-01-26 12:52 GMT+01:00 fugee ohu <fugee279@gmail.com>:
> I can override any gem's controllers and views by creating them in my app?
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/51d6633b-81cc-41ef-b548-575feb06f086%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CANnJYrqXiWCGi8yayXi4OCJSRxq_D4m6Er8fzBbPjf7Ak4%2BuVw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9B5539DE-AE7E-499C-88F4-7DB7B89B7925%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment