how to use controllers and views on many domains - ruby-on-rails

Here is my issue. I need to produce many sites using the same structure (in RoR) and host them on many domains. The only difference between domains will be model data stored in the database and one stylesheet.. everything else will look and operate the same.
I want to be able to structure it so that I only need to change "core.css" in one place to make it update each separate domain. Is there any way that i can do this using ruby on rails? Or is there a better structure i should use?
Thank you,
Troy

Not sure if I fully understand.
I think you want to have multiple domains pointed to the same project. However you want to change the styling depending on the domain.
if so, just name your css style sheets by the domain name.
<link rel="stylesheet" type="text/css" href="/assets/<%= request.request_uri %>.css" />
(that would be a very lazy way)
I would personally, create a function in application controller, which figures out which stylesheet needs to be used. Then output #style variable.
<link rel="stylesheet" type="text/css" href="/assets/<%= #style %>" />

Related

How to avoid Conflicts in Sitefinity MVC Widgets (css and jquery)

I've started developing to sitefinity CMS and I'm having some conflicts when applying styles and Jquery/javascript to Different Widgets.
I want each widget to have its own Style and its Own Jquery and Javascrip functions.
What's happening is that I'm applying in one widget preventDefautls to all its textboxes, and the other widgets' textboxes get affected too.
I'm also applying different css to the widgets and there are conflicts too.
Maybe the good practice is to use the same css to all widgets.
but still when I want to apply something like preventDefaults to all its textboxes, all my widgets get affected.
How can I avoid this?
Im developing ASP.NET MVC Widgets
and this is my widgets structure
<script src="#Url.Content("~/Scripts/jquery-1.11.3.js")"></script>
<link rel="stylesheet" href="~/Content/bootstrap.css" />
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.2.805/styles/kendo.common-bootstrap.min.css" />
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.2.805/styles/kendo.bootstrap.min.css" />
<style>
//addicional style
<style>
<script>
//scripts...
</script>
<div>
Content...
</div>
Some advices about good practices, documentation, or code would be great.
For the styles, I generally wrap my custom widgets with a specific class, eg "imageGallery", and then in my main css (which I manage with grunt/compass), I make sure to target that class explicitly. This way, I can have global style settings, but then also style specific widgets with tweaks. And the nice thing with grunt/compass, is that you can have a separate physical css file for each widget's styles, but they all get bundled together for publishing.
For js, I typically inherit from the SF types, eg "SimpleScriptView", and then override the GetScriptDescriptors(), GetScriptReferences(), etc methods. This allows the scripts to be bundled with the ashx, and cuts down on risk of duplication, etc. It can be a little more complicated to follow the Sitefinity layout of the javascript classes at first, but you'll be consistent with the framework, so you can even decompile SF to get more examples when needed.

What is the advantage of using s:url in link tag

I have seen at couple of places people using the inside the tag to include the css, like below
<link href="<s:url value="path_to_css_file" />" rel="stylesheet" />
What are we gaining from this. We could have easily written the same code without the and things would have worked then also.
It uses the application context (similar to the JSTL tag), but has S2-specific attributes like action, can include/not include current request parameters, etc. (tag docs)
If you're not using any S2-specific functionality when you're using it, I'd use the JSTL equivalent.
I don't really know what will be the difference. All I do know it has something to do with 'struts' and apache.
Hope the source might help you put.
Source: http://struts.apache.org/2.0.11/docs/url.html

Symfony: question about paths

in the cover page (login, register...) of my app i have this line:
<link rel="stylesheet" type="text/css" href="/css/formularios.css">
When i deploy my app, the that css rule is not loaded because, as i can
see in Firebug, it's looking for that rules in
www.tirengarfio.com/css/formularios.css instead of
www.tiregarfio.com/rs2/web/css/formularios.css.
What should i do?
Javi
You should use the view.yml config file and the include_stylesheets() helper. However, if you'd like to create the link tags by hand, use the public_path() helper to get the correct path.

ASP MVC.NET Control css content

I would like to create in my master page a control that depending on the rendered viewpage will change a css file
I was thinking to make a specific controller "CssController" and call this CssController from the src attribute of the css link. This controller will be in charge of choosing the right css and sending it back with text/css header.
question: will this approach break the mvc pattern? Indeed the choose of the design would be in charge of a controller. Is there a better alternative?
What i did in my master page was create a contentplaceholder in the <head> section, as so:
<head runat="server">
<title>Title Here</title>
<script src="<%= Url.Content("~/Scripts/jquery-1.3.2.min.js") %>" type="text/javascript" ></script>
<link href="<%= Url.Content("~/Content/css/site.css") %>" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />
</head>
then, when you create a view using the master page, you can add the view-specific css you want into that content place holder. That way, it'll put your site.css first, plus the desired css, javascript, <script> blocks, whatever, on that particular view.
If you are using separate css files for separate themes, then those would be in fact the view and controller would work. So it does not seem to violate the pattern. But, it does seem to be a more complicated solution than others.
The common way I have seen to do this is with a Jquery Style Switcher
http://www.cssnewbie.com/simple-jquery-stylesheet-switcher/
With a little bit of code you can determine the default style to show on each page
The basic MVC example sets Page Title via the controller. I'm not sure this is any different. If you were using it (for instance) to have users be able to select different skins for their experience, I'm not sure there is any other way to do it, regardless of whether or not it violates the pattern.

how to apply css class to the root folder?

How shall I apply Css Class to the root folder of my mvc application.Because when the application is not given the name of the controller and the start action it is not displaying the images and the css
I think your referring to the reference within link tag in your header?
If this is the case the best solution in my opinion is to use Url.Conent so your link tag will look something like:
<link href="<%=Url.Content( "~/Content/Site.css" ) %>" rel="stylesheet" type="text/css" />
That way no matter what the url the user is viewing the reference to the style sheet is always correct.

Resources