rubymine view html generated by erb rails - ruby-on-rails

Is it possible to see the html generated by html.erb files within RubyMine? I know that I have been able to see the css.min generated by css, so there must be a similar option to be able to see the direct html generated by embedded ruby?

With your Rails server running you can right click a view template file in the project tree and select open in browser
But this is essentially the same as visiting localhost:3000/posts manually, e.g.
Rubymine can't render the view and make the necessary calls to the controller actions and database without the whole app running

Related

Rails load selective contents into view using jquery load function

Recently, I've found this template from codyhouse which I decided to play with it a little in a sample rails app.
Looking into the code, I found that the page transition from the side navigation bar is happening via jquery load function.
From what I understand, whenever view, say user/show, gets loaded in rails, the contents written in the specified url, which in this case would be the contents in my user/show.html.erb file, gets embedded in the application.html.erb file.
As this is the case, I was wondering if there would be a way to "swap" contents being embedded into the application.html.erb file perhaps via jquery load function. For instance, without having to reload the whole view, replace the user/show.html.erb contents loaded in the page with the contents of user/signup.html.erb. Or is it not possible as it deviates from the concept of the MVC model?

How to open a file from Grails app using <a> tag?

This is my first Grails project & I can't seem to do this very simple thing! I am trying to display a list of PDF forms in one page that I have saved under a folder called forms under my_project/grails-app/views/forms and want to open the PDF form in a new window when clicked.
In my .gsp file I am trying to access the forms like this:
Form #1
But that's giving me a 404 error.
I have found couple of solutions like this one or this question (which is very similar to mine)...but first of all, i don't need to upload/download the file. Second, i don't need to render the file either. All I want to do is just click the link and open the PDF file in a new window/tab. Am I saving the PDF files in a wrong place? Please help!! Thank you.
Place your file/directory into grails-app/assets so that you have grails-app/assets/forms/form_one.pdf then you can use the resource tag like this:
Form #1
The grails-app/views directory is used for views rendered by controllers, where as the grails-app/assets directory is used for static and pre-processed assets.

put a rails collection into asset templates

I have a backbone.js front-end and Rails backend, and all my template files are in the assets directory.
I want to implement a select list in one of my templates, with the data coming from a controller.
For example, I have an AccountController and I want the user to be able to select from available accounts. Right now, I've got an AJAX request to build the accounts select list, but that isn't efficient.
Is there a way to inject my Rails data into my templates before the templates are sent to the user?
Assuming you are OK with using mustache.js to render your templates, poirot can do exactly what you're trying to do. With this you can have rails data rendered into the template before rendering the template on the front-end, and you can also use the same mustache template for both back-end and front-end. Keep it DRY yo.
Another way to solve the problem would be to name your JS files like so: example.js.erb, which allow you to render the select HTML or data directly to the JS file, and use it as needed.

Is it possible to render a view file from another website?

I am using Ruby on Rails 3 and I would like to know if it is possible to render a view file (a partial template) from another RoR application (anotherr website). If so, and if the view contains a form, it is possible to submit that form sending information over HTTPS?
Yes.
Here is how you might do it.
Create a symlink from the controller's view folder to the partial in the other application.
ln -s path_to_existing/_existingPartial.html.erb path_to_referring/_existingPartial.html.erb
You can now reference the existingPartial in your views as if it were in the same application.
The form will work as long as the target of the form posts to a valid URL in your current directory.
That said, this isn't the best way to do this. A couple other options:
Create a Rails plugin both apps use
Create a Gem both apps use
Depending on your source control software, you can reference the same file in both source trees (for example, using Subversion external references)
Rails supports rendering an arbitrary file
render "/old_app/current/app/views/pages/show"

problem with panel in ui layout

I am using a simple layout demo in my rails3 application
simple layout demo
in this demo there are 5 panel north,south,east,west,center
when I load my project this all panel show in each and every page.
instead of I want to some specific panel in different different page
give some idea how can i do that
Is the code from the simple layout demo all in your /app/views/layouts/application.html.rb? If so, rails will render everything from that file in every view. Since the jQuery code that does all of the stuff in that demo is in that same file, there may be no easy way to make that work with rails. The only thing I could think to do would be to have different .js files for different pages. each of these separate files would have jQuery code that creates the layout for that page, and is linked to that page using content_for and javascript_include_tag. I'm writing an app that uses jQuery UI and this is how I've had to do it. I created sub folders in my /public/javascripts directory that I named after my models to make it easier to keep all the .js files sorted.

Resources