0

I have a static JSON file called products.json in my public folder in RoR.

as an aside: I have signup and login working.

Moving on, I wonder if I should have just made a products controller to make the user in the views able to render the json. I went into bash and entered rails generate Product with name:string, etc. I wonder if I should have just made a controller only.

Thoughts? So that's where I am

  • And I think I know how to render json. It should be in the products controller. But that controller should go to the User view, yes? Because I want the user to be able to have the products in their account. – swaggiegita Jun 05 '16 at 20:49
  • imho there's nothing wrong with loading a static file from the controller. It's when the data changes (even infrequently) that you should use a model implementation. – DrewT Jun 05 '16 at 21:14
  • What if I just want this application to let user/customer simply look through the products and add it to a checkout cart? I don't want to change the JSON in any way. For now. – swaggiegita Jun 05 '16 at 22:01
  • #/app/controllers/some_controller.rb def schedule render :file => "#{Rails.root}/app/assets/resources/analytics/schedule.json", :content_type => 'application/json', :layout => false end – swaggiegita Jun 05 '16 at 22:22
  • @DrewT Thanks for your advice. – swaggiegita Jun 06 '16 at 01:10
  • @DrewT when logging in, how do I redirect_to the individual user, not users_url? – swaggiegita Jun 06 '16 at 15:53
  • Not sure what you mean by "how do I redirect_to the individual user, not users_url?" but I can say that you just need to create route and a controller for the desired routes you need to redirect to based on your conditions. Regarding redirection based on conditions see this thread: http://stackoverflow.com/questions/11230130/rails-routes-based-on-condition You should probably make a new question if you need further info because I think the nature of what you're asking is now outside the scope of this one (which had to do with how to serve a static json route). – DrewT Jun 06 '16 at 16:45

0 Answers0