All,
Working on a RoR app for work. Finally got acts as tree working with a database connection (railscast.com episode 162). Trying to shift from displaying content in the database to redirecting to the contents of the page.content database entry -- any ideas? I've tried simply replacing the display action with redirect_to, no dice. Googling all over the place - out of time - help..
My flow is as follows:
pages.rb: acts_as_tree command
application.html.erb: menu display for root entries
pages/show.html.erb:
- displays submenu, no problem
- display breadcrumbs, no problem
- display page name, no problem (envision removing this once redirect works)
- display contents of page.content:
<%= simple_format #page.content %>
no problem
Problem is I want to redirect to the contents of #page.content and not display it. Or I can shift to a different controller action, but the idea is that I need to be able to use the navigation menu to move around to different pages (that alrady exist) vs just showing the content. Ideas?
Thanks,
Adam
Related
I have a model that stores a path in the database under a column named "link_path" - for example:
Model.first.link_path == /posts/1
(or, put another way, I am caching the controller/model_id in a database table so Rails doesn't have to build it from scratch.)
In my view, I would like to build up a URL using this path information - for example, http://www.mysite.com/posts/1
I currently have the following code in my view:
<a href="<%= "#{request.protocol}#{request.domain}#{request.port_string}#{post.link_path}" %>">
In development all works as expected both when using POW/Nginx and Webrick - e.g., the link builds up to
http://localhost:3000/posts/1).
However, in production, when I hover over the link, it shows correctly (e.g., mysite.com/posts/1) BUT, when I click on the link, the '/' between .com and posts is strangely missing. The page links to http://mysite.composts/1
Any thoughts on how to fix?
Thanks to BrMcMullin - I wasn't aware I could use the URL helpers without calling the model. Since I don't need the weight of link_to, I ended up changing to
url_for(post.link_path)
instead of manually building up using string interpolation and that seems to work as expected.
I am still pretty new to Rails and am working on a basic app and have run into a problem, which I can't seem to get around, sorry if this question has already been answered, but searching didn't yield me any results.
Basically I am creating an app that catalogues all of someones's clothes, Now the main page is the index page of everything they have logged, and each picture is linked to the show page where more information is revealed. I want to use AJAX to bring that show page to the side of the main index page. I am working off of another tutorial to figure this out but have run into a problem. On the initial load of my index page, I need to define a variable for that show page so that it can be rendered using a partial, but I can't use find(params[:id]) since the user hasn't selected anything yet. So my question is how do I set that initial value to either just the first item in the catalogue or not have anything appear, and then when someone does click the link, the sidebar shows the more detailed description of the piece of clothing.
Thanks for any help.
#object = params[:id] ? MyModel.find(params[:id]) : MyModel.first
But I think there's some problem with design of application.
You might have some luck working with the ruby gem 'PJAX'. Here is a screen cast showing you how to get that AJAX sidebar you want. Good luck
It sounds like you can just print the container element as normal, but leave it empty when the page is generated. Optionally, hide it via CSS. Then, when you load its content with AJAX, set it to visible or just populate it as normal.
Alternatively, if you really want to set it to the first item in the catalog (or in any ActiveRecord) you can use .first e.g. Products.first, and use that value to populate its initial contents.
i have generated a custom engine "Pianos" inside of refinery cms. On the index piano page, I'd like to display the content of a related custom field called "pianos_introduction_text".
What would be the correct way to generate and display this custom field?
Thanks for your help!
Our preference however is to create custom page parts in the normal pages section, rather than to use the copywriting engine.
Under the pages admin section you should see that a page has been added for pianos.
If you add a new page part (or even use an existing one), you can then retrieve and render it from the engine's index page like this:
<%= raw #page.content_for(:new_page_part) %>
I have a view 'edit.html.erb' which renders a partial.
<div id="exerciseslist"><%= render 'exerciseslist' %></div>
Inside 'edit.js.erb', I have the following line which reloads the partial each time something is updated.
$('#exerciseslist').html('<%= escape_javascript(render("exerciseslist")) %>');
The partial is a table with a bunch of items including images for each one and some buttons. All that is changing in the partial is the button. If a submit is successful, the button toggles state indicating that it has been added.
It's working fine, the problem is I don't like the way the images flash as the request happens, the items are also inside a scrollable section which looses it's state each time.
Is there a good way to just load the state of the buttons without rendering the full partial? Or is there a simple way to stop the client requesting the images each time?
I have done some reading and found pjax and backbone.js, are either of them a good way or is there a simpler rails way to do this?
Thanks,
Mike
Without seeing code, it's hard to be sure, but I think it could be done with just Rails. Instead of re-rendering the exerciseslist partial on submission, you could write an AJAX request to handle submission of the new data and on success, have the callback change the button state, rather than reload the partial.
Just like in Gmail, I want to create a div which when loaded with ajax would output a #foo in the address bar to track what content would be loaded.
If you go to https://mail.google.com/mail/?shva=1#sent gmail, if signed in, will take you straight to your sent box.
I want to do the same. For example. I have a div that loads a list of recipes. Once a recipe on the list has been clicked content gets loaded from db in the same div and the address bar would say http://site.com/#recipe-permalink. If this link gets passed to a friend and the friend goes to http://site.com/#recipe-permalink the div would load appropriate content with that recipe.
Also is there a way to control more than one div? For example if url is http://site.com/#recipe-permalink#blue app would load recipe in one div and appropriate content in another div for #blue (what ever it may be).
Is there a way to make cells or apotomo have this functionality?
Are there any SEO concerns with doing this as well? Would the crawlers be able to pick up content through #foo links?
Probably not a full answer to your question but I believe this episode of railscasts would be interesting to you.
http://railscasts.com/episodes/246-ajax-history-state