GithubHelp home page GithubHelp logo

Comments (3)

klebershimabuku avatar klebershimabuku commented on September 1, 2024

Hi @xionon, I like the idea of having this kind of generators, specially this one for scaffold.

Maybe we could have something like an unique scaffold generator for both rails and react.

Assuming react is installed, maybe generate the react scaffold files when running the rails generate scaffold command and generate all the necessary files with just one single command line.

What do you think?

from react-rails.

xionon avatar xionon commented on September 1, 2024

I have been trying to think that through. Let's say you generate a scaffold for Post.

<!-- app/views/posts/show.html.erb -->
<%= react_component 'Post', { post: @post }, { prerender: true } %>

<!-- app/views/posts/index.html.erb -->
<%= react_component 'PostTable', { posts: @posts }, { prerender: true } %>

and PostTable would render a list of PostTableRow objects, keeping with the Rails convention of scaffolding a table for the index view.

Those are pretty easy. The scaffolded edit.html.erb and new.html.erb could be quite similar.

<%= react_component 'PostForm', { post: @post }, { prerender: true } %>

In this example, the form would need to reflect on the post object to determine if it was an edit or new object. Using only Rails' default JSON serializer, I think checking for an id property would be sufficient.

However, I don't think this quite hits the nail on the head. Sure, you get the react_component calls stubbed out for you, but it's not really clear why you would want them in separate ERB templates like that. It leaves the whole question of client-side routing and data updates up to the developer.

e.g., when you click the "show" link from the posts index, you'll just get routed to Rails, which will render the component and send you a new page. You've lost the whole advantage of having a front-end JS library. I think that, if the react-rails gem is going to fully take over the default Rails scaffolds, it should also have an opinion on client-side routing.

Maybe I'm wrong on that, though? Maybe it's totally fine to start with server-side rendering, and let the developers worry about catching clicks and rendering a different component.


Philosophically, SHOULD react-rails provide a front-end routing solution? There are a couple out there, rackt/react-router and andreypopp/react-router-component both look like they should work on the server, but I'm not familiar enough with the JavaScript landscape to know if those are appropriate solutions or not. I could also see the argument that it should be done with a different gem - maybe flex-rails 😎

from react-rails.

klebershimabuku avatar klebershimabuku commented on September 1, 2024

Good question about the front-end routing. I would like to hear from others about this.

flex-rails is a very nice name for a gem. ;)

from react-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.