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"
Related
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
I was developing with cakephp for a few years and now want to try out asp.net mvc.
In cakephp there is a bake plugin, that allows to create standard functionalities based on customizable templates. E.g. changing these templates according to my needs
1) for controller
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Controller/controller.ctp
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Element/Controller/index.ctp
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Element/Controller/add.ctp
2) for model file
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Model/table.ctp
3) for view files
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Template/index.ctp
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Element/form.ctp
I could run a command from CLI and get full functional validation, controller files with actions and view files - based on the existing tables' structures and relations between them. The plugin will create actual php files in corresponding directories with content according to template files. Having pre-customized bake templates allows to generate the CRUD or any other custom functionality in a few minutes.
Is there a similar functionality in asp.net mvc (v5 or above)? The desired features are to be able to fully customize the templates, which will be used to create controllers, cshtml files and model files - assuming that we already have the tables with foreign key associations in the database. (Preferably free, but not necessarily)
Thanks
I think this link might help you with templates in visual studio. If you want to use command line, maybe yeoman can help you. See this link to see if it'll work for you.
I am very new to asp.net MVC.
I need to create dnd file "component". It allows user to upload file to server using DnD, the upload is done via webAPI. I am using FileModel here, for example, webApi also returns FileModel (to show uploaded file info on page). I did this part.
However, I did it in the "TestView". I need ability to add this "component" to any view on my project. Unfourtunately I do not have knowledge enough to do this.
I have found out that there are PartialViews. Should I just move my "TestView" to some "FileUploadPartialView"? What problems this will cause? How this affect the usage of FileModel?
Partial Views are like a javascript include. You shouldn't have any trouble.
Just put this wherever you need to have your partial view...
#Html.Partial("_FileUploadPartialView")
Let me know if you need more detail.
I'm looking for a way to reference a shared external _layout.cshtml from MVC 3 and Razor.
A little back story:
We have multiple developers. All of them are working on separate MVC applications that all need the same look and feel. All these applications will be deployed to the same site for example
http://www.example.com/App1/
and
http://www.example.com/App2/
The look and feel will be generated by the CMS and dropped into a different folder
http://www.example.com/Layout/_layoutExt.cshtml
I've tried
MasterName = #"C:\inetpub\wwwroot\layout\_LayoutExt.cshtml";
But it gives me the error that it can't find the file
The view 'Index' or its master was not
found or no view engine supports the
searched locations. The following
locations were searched.
My eventual solution was to use Symbolic links (or junctions or hard links) to link the needed file into the view folder. This way the CMS writes to one location and my app reads from another. Not the clean solution I was looking for.
You'll probably need to make your own view engine that support reading file outside the web application home directory.
i have a solution with the following two projects - MyNamespace.Services and MyNamespace.Web.
Web contains a MVC web application.
In the Service project i have a EmailService class that takes care of sending out emails to the user.
I want to use either a partial or a view (ascx or aspx) for email templates.
I have found several solutions on how to render a partial view and get the result as a string which works fine if the template is inside the web project (as it is a controller in the web project that calls the email service).
(the 2 methods i am trying to use is either http://developersisland.blogspot.com/2009/01/renderpartial-to-string-in-aspnet-mvc.html (at the bottom of the blog) or http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/)
But my email templates are located in the Services project.
How can i refference the path to the templates (partial/view) in my Service project from inside the Web project, that works with either LoadControl or RenderPartial which both takes a virtual path as a parameter ?
It seems like no matter what i do the root directory is set to the Web projects directory.
Is it possible ?
Would be nice to be able to make it work independently of the web project somehow.
I don't think this is possible without developing your own view engine. The default view engine will only look in certain locations for the partial view -- which includes the current view folder and the shared views folder. I don't think you can search for views outside the current project since those views aren't registered with the view engine.
You can consider just creating your HTML helpers to render emails and return it as a string.
Doesn't really matter whether it is partial view or a method returning a string with HTML. i actually think that for your case helper methods would be a better choice.
A simple helper method is also more flexible in the ways you can use it.
You could try creating a custom view engine locator or virtual path provider. Here are a few examples that may help you get going:
Views in seperate assemblies in ASP.NET MVC
Grouping Controllers with ASP.NET MVC
How to use virtual path providers to dynamically load and compile content from virtual paths in ASP.NET 2.0
All of the links above are good, this might help as well. you will certainly be able to get it to find and use the views. The problem I had was in working with them, there was no code completion etc in the other projects. It was semi possible to get that as well by fiddling around with the project file but to be honest I ended up going with the Grouping solution above
Plug in architecture for ASP.NET MVC